aboutsummaryrefslogtreecommitdiffstats
path: root/src/window.c
diff options
context:
space:
mode:
authorPaul Eggert2020-04-05 01:17:32 -0700
committerPaul Eggert2020-04-05 01:24:36 -0700
commitbec5cfee7660f6e283efbd30a693a6f8e9ea46b8 (patch)
treeb6b872dfb83579336e848a62f720b629426c0ac0 /src/window.c
parent9b8dacdb264412b919782920da916e306102262a (diff)
downloademacs-bec5cfee7660f6e283efbd30a693a6f8e9ea46b8.tar.gz
emacs-bec5cfee7660f6e283efbd30a693a6f8e9ea46b8.zip
Improve integer range checking
* src/bignum.c (check_integer_range, check_uinteger_max) (check_int_nonnegative): New functions. * src/frame.c (check_frame_pixels): New function. (Fset_frame_height, Fset_frame_width, Fset_frame_size): Use it. * src/lisp.h (CHECK_RANGED_INTEGER, CHECK_TYPE_RANGED_INTEGER): Remove these macros. Unless otherwise specified, all callers replaced by calls to check_integer_range, check_uinteger_range, check_int_nonnegative. * src/frame.c (gui_set_right_divider_width) (gui_set_bottom_divider_width): * src/nsfns.m (ns_set_internal_border_width): * src/xfns.c (x_set_internal_border_width): Using check_int_nonnegative means these functions no longer incorrectly reject negative bignums; they treat them as 0, just like negative fixnums.
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c45
1 files changed, 17 insertions, 28 deletions
diff --git a/src/window.c b/src/window.c
index 075fd4e550c..e2dea8b70ef 100644
--- a/src/window.c
+++ b/src/window.c
@@ -2108,30 +2108,20 @@ though when run from an idle timer with a delay of zero seconds. */)
2108 || window_outdated (w)) 2108 || window_outdated (w))
2109 return Qnil; 2109 return Qnil;
2110 2110
2111 if (NILP (first)) 2111 row = (!NILP (first)
2112 row = (NILP (body) 2112 ? MATRIX_ROW (w->current_matrix,
2113 ? MATRIX_ROW (w->current_matrix, 0) 2113 check_integer_range (first, 0,
2114 : MATRIX_FIRST_TEXT_ROW (w->current_matrix)); 2114 w->current_matrix->nrows))
2115 else if (FIXNUMP (first)) 2115 : NILP (body)
2116 { 2116 ? MATRIX_ROW (w->current_matrix, 0)
2117 CHECK_RANGED_INTEGER (first, 0, w->current_matrix->nrows); 2117 : MATRIX_FIRST_TEXT_ROW (w->current_matrix));
2118 row = MATRIX_ROW (w->current_matrix, XFIXNUM (first)); 2118 end_row = (!NILP (last)
2119 } 2119 ? MATRIX_ROW (w->current_matrix,
2120 else 2120 check_integer_range (last, 0,
2121 error ("Invalid specification of first line"); 2121 w->current_matrix->nrows))
2122 2122 : NILP (body)
2123 if (NILP (last)) 2123 ? MATRIX_ROW (w->current_matrix, w->current_matrix->nrows)
2124 2124 : MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w));
2125 end_row = (NILP (body)
2126 ? MATRIX_ROW (w->current_matrix, w->current_matrix->nrows)
2127 : MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w));
2128 else if (FIXNUMP (last))
2129 {
2130 CHECK_RANGED_INTEGER (last, 0, w->current_matrix->nrows);
2131 end_row = MATRIX_ROW (w->current_matrix, XFIXNUM (last));
2132 }
2133 else
2134 error ("Invalid specification of last line");
2135 2125
2136 while (row <= end_row && row->enabled_p 2126 while (row <= end_row && row->enabled_p
2137 && row->y + row->height < max_y) 2127 && row->y + row->height < max_y)
@@ -4325,11 +4315,11 @@ Note: This function does not operate on any child windows of WINDOW. */)
4325 EMACS_INT size_min = NILP (add) ? 0 : - XFIXNUM (w->new_pixel); 4315 EMACS_INT size_min = NILP (add) ? 0 : - XFIXNUM (w->new_pixel);
4326 EMACS_INT size_max = size_min + min (INT_MAX, MOST_POSITIVE_FIXNUM); 4316 EMACS_INT size_max = size_min + min (INT_MAX, MOST_POSITIVE_FIXNUM);
4327 4317
4328 CHECK_RANGED_INTEGER (size, size_min, size_max); 4318 int checked_size = check_integer_range (size, size_min, size_max);
4329 if (NILP (add)) 4319 if (NILP (add))
4330 wset_new_pixel (w, size); 4320 wset_new_pixel (w, size);
4331 else 4321 else
4332 wset_new_pixel (w, make_fixnum (XFIXNUM (w->new_pixel) + XFIXNUM (size))); 4322 wset_new_pixel (w, make_fixnum (XFIXNUM (w->new_pixel) + checked_size));
4333 4323
4334 return w->new_pixel; 4324 return w->new_pixel;
4335} 4325}
@@ -7506,8 +7496,7 @@ extract_dimension (Lisp_Object dimension)
7506{ 7496{
7507 if (NILP (dimension)) 7497 if (NILP (dimension))
7508 return -1; 7498 return -1;
7509 CHECK_RANGED_INTEGER (dimension, 0, INT_MAX); 7499 return check_integer_range (dimension, 0, INT_MAX);
7510 return XFIXNUM (dimension);
7511} 7500}
7512 7501
7513static struct window * 7502static struct window *