aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2020-04-05 01:17:32 -0700
committerPaul Eggert2020-04-05 01:24:36 -0700
commitbec5cfee7660f6e283efbd30a693a6f8e9ea46b8 (patch)
treeb6b872dfb83579336e848a62f720b629426c0ac0
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.
-rw-r--r--src/bignum.c36
-rw-r--r--src/character.c5
-rw-r--r--src/charset.c33
-rw-r--r--src/coding.c8
-rw-r--r--src/fileio.c4
-rw-r--r--src/frame.c99
-rw-r--r--src/lcms.c3
-rw-r--r--src/lisp.h19
-rw-r--r--src/menu.c22
-rw-r--r--src/nsfns.m19
-rw-r--r--src/process.c13
-rw-r--r--src/search.c9
-rw-r--r--src/w32fns.c12
-rw-r--r--src/window.c45
-rw-r--r--src/xfns.c30
-rw-r--r--src/xwidget.c6
16 files changed, 158 insertions, 205 deletions
diff --git a/src/bignum.c b/src/bignum.c
index 51d90ffaefa..859896cdcf7 100644
--- a/src/bignum.c
+++ b/src/bignum.c
@@ -431,3 +431,39 @@ make_bignum_str (char const *num, int base)
431 eassert (check == 0); 431 eassert (check == 0);
432 return make_lisp_ptr (b, Lisp_Vectorlike); 432 return make_lisp_ptr (b, Lisp_Vectorlike);
433} 433}
434
435/* Check that X is a Lisp integer in the range LO..HI.
436 Return X's value as an intmax_t. */
437
438intmax_t
439check_integer_range (Lisp_Object x, intmax_t lo, intmax_t hi)
440{
441 CHECK_INTEGER (x);
442 intmax_t i;
443 if (! (integer_to_intmax (x, &i) && lo <= i && i <= hi))
444 args_out_of_range_3 (x, make_int (lo), make_int (hi));
445 return i;
446}
447
448/* Check that X is a Lisp integer in the range 0..HI.
449 Return X's value as an uintmax_t. */
450
451uintmax_t
452check_uinteger_max (Lisp_Object x, uintmax_t hi)
453{
454 CHECK_INTEGER (x);
455 uintmax_t i;
456 if (! (integer_to_uintmax (x, &i) && i <= hi))
457 args_out_of_range_3 (x, make_fixnum (0), make_uint (hi));
458 return i;
459}
460
461/* Check that X is a Lisp integer no greater than INT_MAX,
462 and return its value or zero, whichever is greater. */
463
464int
465check_int_nonnegative (Lisp_Object x)
466{
467 CHECK_INTEGER (x);
468 return Fnatnump (x) ? check_integer_range (x, 0, INT_MAX) : 0;
469}
diff --git a/src/character.c b/src/character.c
index a566cacb023..c938e9fe412 100644
--- a/src/character.c
+++ b/src/character.c
@@ -876,10 +876,7 @@ usage: (unibyte-string &rest BYTES) */)
876 Lisp_Object str = make_uninit_string (n); 876 Lisp_Object str = make_uninit_string (n);
877 unsigned char *p = SDATA (str); 877 unsigned char *p = SDATA (str);
878 for (ptrdiff_t i = 0; i < n; i++) 878 for (ptrdiff_t i = 0; i < n; i++)
879 { 879 *p++ = check_integer_range (args[i], 0, 255);
880 CHECK_RANGED_INTEGER (args[i], 0, 255);
881 *p++ = XFIXNUM (args[i]);
882 }
883 return str; 880 return str;
884} 881}
885 882
diff --git a/src/charset.c b/src/charset.c
index 2771b0ba2ac..9e55d0c7fef 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -866,15 +866,10 @@ usage: (define-charset-internal ...) */)
866 val = args[charset_arg_code_space]; 866 val = args[charset_arg_code_space];
867 for (i = 0, dimension = 0, nchars = 1; ; i++) 867 for (i = 0, dimension = 0, nchars = 1; ; i++)
868 { 868 {
869 Lisp_Object min_byte_obj, max_byte_obj; 869 Lisp_Object min_byte_obj = Faref (val, make_fixnum (i * 2));
870 int min_byte, max_byte; 870 Lisp_Object max_byte_obj = Faref (val, make_fixnum (i * 2 + 1));
871 871 int min_byte = check_integer_range (min_byte_obj, 0, 255);
872 min_byte_obj = Faref (val, make_fixnum (i * 2)); 872 int max_byte = check_integer_range (max_byte_obj, min_byte, 255);
873 max_byte_obj = Faref (val, make_fixnum (i * 2 + 1));
874 CHECK_RANGED_INTEGER (min_byte_obj, 0, 255);
875 min_byte = XFIXNUM (min_byte_obj);
876 CHECK_RANGED_INTEGER (max_byte_obj, min_byte, 255);
877 max_byte = XFIXNUM (max_byte_obj);
878 charset.code_space[i * 4] = min_byte; 873 charset.code_space[i * 4] = min_byte;
879 charset.code_space[i * 4 + 1] = max_byte; 874 charset.code_space[i * 4 + 1] = max_byte;
880 charset.code_space[i * 4 + 2] = max_byte - min_byte + 1; 875 charset.code_space[i * 4 + 2] = max_byte - min_byte + 1;
@@ -887,13 +882,8 @@ usage: (define-charset-internal ...) */)
887 } 882 }
888 883
889 val = args[charset_arg_dimension]; 884 val = args[charset_arg_dimension];
890 if (NILP (val)) 885 charset.dimension
891 charset.dimension = dimension; 886 = !NILP (val) ? check_integer_range (val, 1, 4) : dimension;
892 else
893 {
894 CHECK_RANGED_INTEGER (val, 1, 4);
895 charset.dimension = XFIXNUM (val);
896 }
897 887
898 charset.code_linear_p 888 charset.code_linear_p
899 = (charset.dimension == 1 889 = (charset.dimension == 1
@@ -979,13 +969,7 @@ usage: (define-charset-internal ...) */)
979 } 969 }
980 970
981 val = args[charset_arg_iso_revision]; 971 val = args[charset_arg_iso_revision];
982 if (NILP (val)) 972 charset.iso_revision = !NILP (val) ? check_integer_range (val, -1, 63) : -1;
983 charset.iso_revision = -1;
984 else
985 {
986 CHECK_RANGED_INTEGER (val, -1, 63);
987 charset.iso_revision = XFIXNUM (val);
988 }
989 973
990 val = args[charset_arg_emacs_mule_id]; 974 val = args[charset_arg_emacs_mule_id];
991 if (NILP (val)) 975 if (NILP (val))
@@ -1090,8 +1074,7 @@ usage: (define-charset-internal ...) */)
1090 car_part = XCAR (elt); 1074 car_part = XCAR (elt);
1091 cdr_part = XCDR (elt); 1075 cdr_part = XCDR (elt);
1092 CHECK_CHARSET_GET_ID (car_part, this_id); 1076 CHECK_CHARSET_GET_ID (car_part, this_id);
1093 CHECK_TYPE_RANGED_INTEGER (int, cdr_part); 1077 offset = check_integer_range (cdr_part, INT_MIN, INT_MAX);
1094 offset = XFIXNUM (cdr_part);
1095 } 1078 }
1096 else 1079 else
1097 { 1080 {
diff --git a/src/coding.c b/src/coding.c
index 0bea2a0c2bc..f0fc37dbdfa 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -11061,10 +11061,8 @@ usage: (define-coding-system-internal ...) */)
11061 else 11061 else
11062 { 11062 {
11063 CHECK_CONS (val); 11063 CHECK_CONS (val);
11064 CHECK_RANGED_INTEGER (XCAR (val), 0, 255); 11064 from = check_integer_range (XCAR (val), 0, 255);
11065 from = XFIXNUM (XCAR (val)); 11065 to = check_integer_range (XCDR (val), from, 255);
11066 CHECK_RANGED_INTEGER (XCDR (val), from, 255);
11067 to = XFIXNUM (XCDR (val));
11068 } 11066 }
11069 for (int i = from; i <= to; i++) 11067 for (int i = from; i <= to; i++)
11070 SSET (valids, i, 1); 11068 SSET (valids, i, 1);
@@ -11149,7 +11147,7 @@ usage: (define-coding-system-internal ...) */)
11149 val = XCAR (tail); 11147 val = XCAR (tail);
11150 CHECK_CONS (val); 11148 CHECK_CONS (val);
11151 CHECK_CHARSET_GET_ID (XCAR (val), id); 11149 CHECK_CHARSET_GET_ID (XCAR (val), id);
11152 CHECK_RANGED_INTEGER (XCDR (val), 0, 3); 11150 check_integer_range (XCDR (val), 0, 3);
11153 XSETCAR (val, make_fixnum (id)); 11151 XSETCAR (val, make_fixnum (id));
11154 } 11152 }
11155 11153
diff --git a/src/fileio.c b/src/fileio.c
index 978a373d39b..2f1d2f82433 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -5682,8 +5682,8 @@ in `current-time' or an integer flag as returned by `visited-file-modtime'. */)
5682 struct timespec mtime; 5682 struct timespec mtime;
5683 if (FIXNUMP (time_flag)) 5683 if (FIXNUMP (time_flag))
5684 { 5684 {
5685 CHECK_RANGED_INTEGER (time_flag, -1, 0); 5685 int flag = check_integer_range (time_flag, -1, 0);
5686 mtime = make_timespec (0, UNKNOWN_MODTIME_NSECS - XFIXNUM (time_flag)); 5686 mtime = make_timespec (0, UNKNOWN_MODTIME_NSECS - flag);
5687 } 5687 }
5688 else 5688 else
5689 mtime = lisp_time_argument (time_flag); 5689 mtime = lisp_time_argument (time_flag);
diff --git a/src/frame.c b/src/frame.c
index c7e4f2f6bd9..884de2f5349 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -2558,26 +2558,26 @@ before calling this function on it, like this.
2558 (Lisp_Object frame, Lisp_Object x, Lisp_Object y) 2558 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2559{ 2559{
2560 CHECK_LIVE_FRAME (frame); 2560 CHECK_LIVE_FRAME (frame);
2561 CHECK_TYPE_RANGED_INTEGER (int, x); 2561 int xval = check_integer_range (x, INT_MIN, INT_MAX);
2562 CHECK_TYPE_RANGED_INTEGER (int, y); 2562 int yval = check_integer_range (y, INT_MIN, INT_MAX);
2563 2563
2564 /* I think this should be done with a hook. */ 2564 /* I think this should be done with a hook. */
2565#ifdef HAVE_WINDOW_SYSTEM 2565#ifdef HAVE_WINDOW_SYSTEM
2566 if (FRAME_WINDOW_P (XFRAME (frame))) 2566 if (FRAME_WINDOW_P (XFRAME (frame)))
2567 /* Warping the mouse will cause enternotify and focus events. */ 2567 /* Warping the mouse will cause enternotify and focus events. */
2568 frame_set_mouse_position (XFRAME (frame), XFIXNUM (x), XFIXNUM (y)); 2568 frame_set_mouse_position (XFRAME (frame), xval, yval);
2569#else 2569#else
2570#if defined (MSDOS) 2570#if defined (MSDOS)
2571 if (FRAME_MSDOS_P (XFRAME (frame))) 2571 if (FRAME_MSDOS_P (XFRAME (frame)))
2572 { 2572 {
2573 Fselect_frame (frame, Qnil); 2573 Fselect_frame (frame, Qnil);
2574 mouse_moveto (XFIXNUM (x), XFIXNUM (y)); 2574 mouse_moveto (xval, yval);
2575 } 2575 }
2576#else 2576#else
2577#ifdef HAVE_GPM 2577#ifdef HAVE_GPM
2578 { 2578 {
2579 Fselect_frame (frame, Qnil); 2579 Fselect_frame (frame, Qnil);
2580 term_mouse_moveto (XFIXNUM (x), XFIXNUM (y)); 2580 term_mouse_moveto (xval, yval);
2581 } 2581 }
2582#endif 2582#endif
2583#endif 2583#endif
@@ -2599,26 +2599,26 @@ before calling this function on it, like this.
2599 (Lisp_Object frame, Lisp_Object x, Lisp_Object y) 2599 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2600{ 2600{
2601 CHECK_LIVE_FRAME (frame); 2601 CHECK_LIVE_FRAME (frame);
2602 CHECK_TYPE_RANGED_INTEGER (int, x); 2602 int xval = check_integer_range (x, INT_MIN, INT_MAX);
2603 CHECK_TYPE_RANGED_INTEGER (int, y); 2603 int yval = check_integer_range (y, INT_MIN, INT_MAX);
2604 2604
2605 /* I think this should be done with a hook. */ 2605 /* I think this should be done with a hook. */
2606#ifdef HAVE_WINDOW_SYSTEM 2606#ifdef HAVE_WINDOW_SYSTEM
2607 if (FRAME_WINDOW_P (XFRAME (frame))) 2607 if (FRAME_WINDOW_P (XFRAME (frame)))
2608 /* Warping the mouse will cause enternotify and focus events. */ 2608 /* Warping the mouse will cause enternotify and focus events. */
2609 frame_set_mouse_pixel_position (XFRAME (frame), XFIXNUM (x), XFIXNUM (y)); 2609 frame_set_mouse_pixel_position (XFRAME (frame), xval, yval);
2610#else 2610#else
2611#if defined (MSDOS) 2611#if defined (MSDOS)
2612 if (FRAME_MSDOS_P (XFRAME (frame))) 2612 if (FRAME_MSDOS_P (XFRAME (frame)))
2613 { 2613 {
2614 Fselect_frame (frame, Qnil); 2614 Fselect_frame (frame, Qnil);
2615 mouse_moveto (XFIXNUM (x), XFIXNUM (y)); 2615 mouse_moveto (xval, yval);
2616 } 2616 }
2617#else 2617#else
2618#ifdef HAVE_GPM 2618#ifdef HAVE_GPM
2619 { 2619 {
2620 Fselect_frame (frame, Qnil); 2620 Fselect_frame (frame, Qnil);
2621 term_mouse_moveto (XFIXNUM (x), XFIXNUM (y)); 2621 term_mouse_moveto (xval, yval);
2622 } 2622 }
2623#endif 2623#endif
2624#endif 2624#endif
@@ -3545,6 +3545,21 @@ DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_widt
3545 return make_fixnum (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame))); 3545 return make_fixnum (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
3546} 3546}
3547 3547
3548static int
3549check_frame_pixels (Lisp_Object size, Lisp_Object pixelwise, int item_size)
3550{
3551 CHECK_INTEGER (size);
3552 if (!NILP (pixelwise))
3553 item_size = 1;
3554 intmax_t sz;
3555 int pixel_size; /* size * item_size */
3556 if (! integer_to_intmax (size, &sz)
3557 || INT_MULTIPLY_WRAPV (sz, item_size, &pixel_size))
3558 args_out_of_range_3 (size, make_int (INT_MIN / item_size),
3559 make_int (INT_MAX / item_size));
3560 return pixel_size;
3561}
3562
3548DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 3563DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4,
3549 "(list (selected-frame) (prefix-numeric-value current-prefix-arg))", 3564 "(list (selected-frame) (prefix-numeric-value current-prefix-arg))",
3550 doc: /* Set text height of frame FRAME to HEIGHT lines. 3565 doc: /* Set text height of frame FRAME to HEIGHT lines.
@@ -3562,15 +3577,9 @@ currently selected frame will be set to this height. */)
3562 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise) 3577 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
3563{ 3578{
3564 struct frame *f = decode_live_frame (frame); 3579 struct frame *f = decode_live_frame (frame);
3565 int pixel_height; 3580 int pixel_height = check_frame_pixels (height, pixelwise,
3566 3581 FRAME_LINE_HEIGHT (f));
3567 CHECK_TYPE_RANGED_INTEGER (int, height);
3568
3569 pixel_height = (!NILP (pixelwise)
3570 ? XFIXNUM (height)
3571 : XFIXNUM (height) * FRAME_LINE_HEIGHT (f));
3572 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight); 3582 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
3573
3574 return Qnil; 3583 return Qnil;
3575} 3584}
3576 3585
@@ -3591,15 +3600,9 @@ currently selected frame will be set to this width. */)
3591 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise) 3600 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
3592{ 3601{
3593 struct frame *f = decode_live_frame (frame); 3602 struct frame *f = decode_live_frame (frame);
3594 int pixel_width; 3603 int pixel_width = check_frame_pixels (width, pixelwise,
3595 3604 FRAME_COLUMN_WIDTH (f));
3596 CHECK_TYPE_RANGED_INTEGER (int, width);
3597
3598 pixel_width = (!NILP (pixelwise)
3599 ? XFIXNUM (width)
3600 : XFIXNUM (width) * FRAME_COLUMN_WIDTH (f));
3601 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth); 3605 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
3602
3603 return Qnil; 3606 return Qnil;
3604} 3607}
3605 3608
@@ -3613,19 +3616,11 @@ font height. */)
3613 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise) 3616 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
3614{ 3617{
3615 struct frame *f = decode_live_frame (frame); 3618 struct frame *f = decode_live_frame (frame);
3616 int pixel_width, pixel_height; 3619 int pixel_width = check_frame_pixels (width, pixelwise,
3617 3620 FRAME_COLUMN_WIDTH (f));
3618 CHECK_TYPE_RANGED_INTEGER (int, width); 3621 int pixel_height = check_frame_pixels (height, pixelwise,
3619 CHECK_TYPE_RANGED_INTEGER (int, height); 3622 FRAME_LINE_HEIGHT (f));
3620
3621 pixel_width = (!NILP (pixelwise)
3622 ? XFIXNUM (width)
3623 : XFIXNUM (width) * FRAME_COLUMN_WIDTH (f));
3624 pixel_height = (!NILP (pixelwise)
3625 ? XFIXNUM (height)
3626 : XFIXNUM (height) * FRAME_LINE_HEIGHT (f));
3627 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize); 3623 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
3628
3629 return Qnil; 3624 return Qnil;
3630} 3625}
3631 3626
@@ -3655,18 +3650,14 @@ bottom edge of FRAME's display. */)
3655 (Lisp_Object frame, Lisp_Object x, Lisp_Object y) 3650 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
3656{ 3651{
3657 struct frame *f = decode_live_frame (frame); 3652 struct frame *f = decode_live_frame (frame);
3658 3653 int xval = check_integer_range (x, INT_MIN, INT_MAX);
3659 CHECK_TYPE_RANGED_INTEGER (int, x); 3654 int yval = check_integer_range (y, INT_MIN, INT_MAX);
3660 CHECK_TYPE_RANGED_INTEGER (int, y);
3661 3655
3662 if (FRAME_WINDOW_P (f)) 3656 if (FRAME_WINDOW_P (f))
3663 { 3657 {
3664#ifdef HAVE_WINDOW_SYSTEM 3658#ifdef HAVE_WINDOW_SYSTEM
3665 if (FRAME_TERMINAL (f)->set_frame_offset_hook) 3659 if (FRAME_TERMINAL (f)->set_frame_offset_hook)
3666 FRAME_TERMINAL (f)->set_frame_offset_hook (f, 3660 FRAME_TERMINAL (f)->set_frame_offset_hook (f, xval, yval, 1);
3667 XFIXNUM (x),
3668 XFIXNUM (y),
3669 1);
3670#endif 3661#endif
3671 } 3662 }
3672 3663
@@ -4641,23 +4632,22 @@ gui_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_va
4641void 4632void
4642gui_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 4633gui_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4643{ 4634{
4644 CHECK_TYPE_RANGED_INTEGER (int, arg); 4635 int border_width = check_integer_range (arg, INT_MIN, INT_MAX);
4645 4636
4646 if (XFIXNUM (arg) == f->border_width) 4637 if (border_width == f->border_width)
4647 return; 4638 return;
4648 4639
4649 if (FRAME_NATIVE_WINDOW (f) != 0) 4640 if (FRAME_NATIVE_WINDOW (f) != 0)
4650 error ("Cannot change the border width of a frame"); 4641 error ("Cannot change the border width of a frame");
4651 4642
4652 f->border_width = XFIXNUM (arg); 4643 f->border_width = border_width;
4653} 4644}
4654 4645
4655void 4646void
4656gui_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 4647gui_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4657{ 4648{
4658 int old = FRAME_RIGHT_DIVIDER_WIDTH (f); 4649 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
4659 CHECK_TYPE_RANGED_INTEGER (int, arg); 4650 int new = check_int_nonnegative (arg);
4660 int new = max (0, XFIXNUM (arg));
4661 if (new != old) 4651 if (new != old)
4662 { 4652 {
4663 f->right_divider_width = new; 4653 f->right_divider_width = new;
@@ -4671,8 +4661,7 @@ void
4671gui_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 4661gui_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4672{ 4662{
4673 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f); 4663 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
4674 CHECK_TYPE_RANGED_INTEGER (int, arg); 4664 int new = check_int_nonnegative (arg);
4675 int new = max (0, XFIXNUM (arg));
4676 if (new != old) 4665 if (new != old)
4677 { 4666 {
4678 f->bottom_divider_width = new; 4667 f->bottom_divider_width = new;
@@ -5651,8 +5640,7 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p,
5651 f->top_pos = 0; 5640 f->top_pos = 0;
5652 else 5641 else
5653 { 5642 {
5654 CHECK_TYPE_RANGED_INTEGER (int, top); 5643 f->top_pos = check_integer_range (top, INT_MIN, INT_MAX);
5655 f->top_pos = XFIXNUM (top);
5656 if (f->top_pos < 0) 5644 if (f->top_pos < 0)
5657 window_prompting |= YNegative; 5645 window_prompting |= YNegative;
5658 } 5646 }
@@ -5682,8 +5670,7 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p,
5682 f->left_pos = 0; 5670 f->left_pos = 0;
5683 else 5671 else
5684 { 5672 {
5685 CHECK_TYPE_RANGED_INTEGER (int, left); 5673 f->left_pos = check_integer_range (left, INT_MIN, INT_MAX);
5686 f->left_pos = XFIXNUM (left);
5687 if (f->left_pos < 0) 5674 if (f->left_pos < 0)
5688 window_prompting |= XNegative; 5675 window_prompting |= XNegative;
5689 } 5676 }
diff --git a/src/lcms.c b/src/lcms.c
index c19397f4baa..924bdd299dc 100644
--- a/src/lcms.c
+++ b/src/lcms.c
@@ -254,8 +254,7 @@ parse_viewing_conditions (Lisp_Object view, const cmsCIEXYZ *wp,
254#define PARSE_VIEW_CONDITION_INT(field) \ 254#define PARSE_VIEW_CONDITION_INT(field) \
255 if (CONSP (view) && FIXNATP (XCAR (view))) \ 255 if (CONSP (view) && FIXNATP (XCAR (view))) \
256 { \ 256 { \
257 CHECK_RANGED_INTEGER (XCAR (view), 1, 4); \ 257 vc->field = check_integer_range (XCAR (view), 1, 4); \
258 vc->field = XFIXNUM (XCAR (view)); \
259 view = XCDR (view); \ 258 view = XCDR (view); \
260 } \ 259 } \
261 else \ 260 else \
diff --git a/src/lisp.h b/src/lisp.h
index 23ff89a9778..c3efabaf528 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -589,15 +589,19 @@ INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t,
589 Lisp_Object); 589 Lisp_Object);
590 590
591/* Defined in bignum.c. */ 591/* Defined in bignum.c. */
592extern int check_int_nonnegative (Lisp_Object);
593extern intmax_t check_integer_range (Lisp_Object, intmax_t, intmax_t);
592extern double bignum_to_double (Lisp_Object) ATTRIBUTE_CONST; 594extern double bignum_to_double (Lisp_Object) ATTRIBUTE_CONST;
593extern Lisp_Object make_bigint (intmax_t); 595extern Lisp_Object make_bigint (intmax_t);
594extern Lisp_Object make_biguint (uintmax_t); 596extern Lisp_Object make_biguint (uintmax_t);
597extern uintmax_t check_uinteger_max (Lisp_Object, uintmax_t);
595 598
596/* Defined in chartab.c. */ 599/* Defined in chartab.c. */
597extern Lisp_Object char_table_ref (Lisp_Object, int); 600extern Lisp_Object char_table_ref (Lisp_Object, int);
598extern void char_table_set (Lisp_Object, int, Lisp_Object); 601extern void char_table_set (Lisp_Object, int, Lisp_Object);
599 602
600/* Defined in data.c. */ 603/* Defined in data.c. */
604extern AVOID args_out_of_range_3 (Lisp_Object, Lisp_Object, Lisp_Object);
601extern AVOID wrong_type_argument (Lisp_Object, Lisp_Object); 605extern AVOID wrong_type_argument (Lisp_Object, Lisp_Object);
602extern Lisp_Object default_value (Lisp_Object symbol); 606extern Lisp_Object default_value (Lisp_Object symbol);
603 607
@@ -3002,20 +3006,6 @@ CHECK_FIXNAT (Lisp_Object x)
3002 CHECK_TYPE (FIXNATP (x), Qwholenump, x); 3006 CHECK_TYPE (FIXNATP (x), Qwholenump, x);
3003} 3007}
3004 3008
3005#define CHECK_RANGED_INTEGER(x, lo, hi) \
3006 do { \
3007 CHECK_FIXNUM (x); \
3008 if (! ((lo) <= XFIXNUM (x) && XFIXNUM (x) <= (hi))) \
3009 args_out_of_range_3 (x, INT_TO_INTEGER (lo), INT_TO_INTEGER (hi)); \
3010 } while (false)
3011#define CHECK_TYPE_RANGED_INTEGER(type, x) \
3012 do { \
3013 if (TYPE_SIGNED (type)) \
3014 CHECK_RANGED_INTEGER (x, TYPE_MINIMUM (type), TYPE_MAXIMUM (type)); \
3015 else \
3016 CHECK_RANGED_INTEGER (x, 0, TYPE_MAXIMUM (type)); \
3017 } while (false)
3018
3019INLINE double 3009INLINE double
3020XFLOATINT (Lisp_Object n) 3010XFLOATINT (Lisp_Object n)
3021{ 3011{
@@ -3581,7 +3571,6 @@ extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t);
3581 3571
3582extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *); 3572extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *);
3583extern AVOID args_out_of_range (Lisp_Object, Lisp_Object); 3573extern AVOID args_out_of_range (Lisp_Object, Lisp_Object);
3584extern AVOID args_out_of_range_3 (Lisp_Object, Lisp_Object, Lisp_Object);
3585extern AVOID circular_list (Lisp_Object); 3574extern AVOID circular_list (Lisp_Object);
3586extern Lisp_Object do_symval_forwarding (lispfwd); 3575extern Lisp_Object do_symval_forwarding (lispfwd);
3587enum Set_Internal_Bind { 3576enum Set_Internal_Bind {
diff --git a/src/menu.c b/src/menu.c
index 28bfcae05d6..6b8b5dd1210 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -1253,18 +1253,16 @@ x_popup_menu_1 (Lisp_Object position, Lisp_Object menu)
1253 but I don't want to make one now. */ 1253 but I don't want to make one now. */
1254 CHECK_WINDOW (window); 1254 CHECK_WINDOW (window);
1255 1255
1256 CHECK_RANGED_INTEGER (x, 1256 xpos += check_integer_range (x,
1257 (xpos < INT_MIN - MOST_NEGATIVE_FIXNUM 1257 (xpos < INT_MIN - MOST_NEGATIVE_FIXNUM
1258 ? (EMACS_INT) INT_MIN - xpos 1258 ? (EMACS_INT) INT_MIN - xpos
1259 : MOST_NEGATIVE_FIXNUM), 1259 : MOST_NEGATIVE_FIXNUM),
1260 INT_MAX - xpos); 1260 INT_MAX - xpos);
1261 CHECK_RANGED_INTEGER (y, 1261 ypos += check_integer_range (y,
1262 (ypos < INT_MIN - MOST_NEGATIVE_FIXNUM 1262 (ypos < INT_MIN - MOST_NEGATIVE_FIXNUM
1263 ? (EMACS_INT) INT_MIN - ypos 1263 ? (EMACS_INT) INT_MIN - ypos
1264 : MOST_NEGATIVE_FIXNUM), 1264 : MOST_NEGATIVE_FIXNUM),
1265 INT_MAX - ypos); 1265 INT_MAX - ypos);
1266 xpos += XFIXNUM (x);
1267 ypos += XFIXNUM (y);
1268 1266
1269 XSETFRAME (Vmenu_updating_frame, f); 1267 XSETFRAME (Vmenu_updating_frame, f);
1270 } 1268 }
diff --git a/src/nsfns.m b/src/nsfns.m
index f6e7f4e9acb..273fb5f7598 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -706,14 +706,11 @@ static void
706ns_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 706ns_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
707{ 707{
708 int old_width = FRAME_INTERNAL_BORDER_WIDTH (f); 708 int old_width = FRAME_INTERNAL_BORDER_WIDTH (f);
709 int new_width = check_int_nonnegative (arg);
709 710
710 CHECK_TYPE_RANGED_INTEGER (int, arg); 711 if (new_width == old_width)
711 f->internal_border_width = XFIXNUM (arg);
712 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
713 f->internal_border_width = 0;
714
715 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old_width)
716 return; 712 return;
713 f->internal_border_width = new_width;
717 714
718 if (FRAME_NATIVE_WINDOW (f) != 0) 715 if (FRAME_NATIVE_WINDOW (f) != 0)
719 adjust_frame_size (f, -1, -1, 3, 0, Qinternal_border_width); 716 adjust_frame_size (f, -1, -1, 3, 0, Qinternal_border_width);
@@ -2956,16 +2953,16 @@ The coordinates X and Y are interpreted in pixels relative to a position
2956 if (FRAME_INITIAL_P (f) || !FRAME_NS_P (f)) 2953 if (FRAME_INITIAL_P (f) || !FRAME_NS_P (f))
2957 return Qnil; 2954 return Qnil;
2958 2955
2959 CHECK_TYPE_RANGED_INTEGER (int, x); 2956 int xval = check_integer_range (x, INT_MIN, INT_MAX);
2960 CHECK_TYPE_RANGED_INTEGER (int, y); 2957 int yval = check_integer_range (y, INT_MIN, INT_MAX);
2961 2958
2962 mouse_x = screen_frame.origin.x + XFIXNUM (x); 2959 mouse_x = screen_frame.origin.x + xval;
2963 2960
2964 if (screen == primary_screen) 2961 if (screen == primary_screen)
2965 mouse_y = screen_frame.origin.y + XFIXNUM (y); 2962 mouse_y = screen_frame.origin.y + yval;
2966 else 2963 else
2967 mouse_y = (primary_screen_height - screen_frame.size.height 2964 mouse_y = (primary_screen_height - screen_frame.size.height
2968 - screen_frame.origin.y) + XFIXNUM (y); 2965 - screen_frame.origin.y) + yval;
2969 2966
2970 CGPoint mouse_pos = CGPointMake(mouse_x, mouse_y); 2967 CGPoint mouse_pos = CGPointMake(mouse_x, mouse_y);
2971 CGWarpMouseCursorPosition (mouse_pos); 2968 CGWarpMouseCursorPosition (mouse_pos);
diff --git a/src/process.c b/src/process.c
index e6d18fbaad2..6e5bcf307ab 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1392,14 +1392,12 @@ nil otherwise. */)
1392 CHECK_PROCESS (process); 1392 CHECK_PROCESS (process);
1393 1393
1394 /* All known platforms store window sizes as 'unsigned short'. */ 1394 /* All known platforms store window sizes as 'unsigned short'. */
1395 CHECK_RANGED_INTEGER (height, 0, USHRT_MAX); 1395 unsigned short h = check_uinteger_max (height, USHRT_MAX);
1396 CHECK_RANGED_INTEGER (width, 0, USHRT_MAX); 1396 unsigned short w = check_uinteger_max (width, USHRT_MAX);
1397 1397
1398 if (NETCONN_P (process) 1398 if (NETCONN_P (process)
1399 || XPROCESS (process)->infd < 0 1399 || XPROCESS (process)->infd < 0
1400 || (set_window_size (XPROCESS (process)->infd, 1400 || set_window_size (XPROCESS (process)->infd, h, w) < 0)
1401 XFIXNUM (height), XFIXNUM (width))
1402 < 0))
1403 return Qnil; 1401 return Qnil;
1404 else 1402 else
1405 return Qt; 1403 return Qt;
@@ -7075,10 +7073,7 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
7075 } 7073 }
7076 7074
7077 if (FIXNUMP (sigcode)) 7075 if (FIXNUMP (sigcode))
7078 { 7076 signo = check_integer_range (sigcode, INT_MIN, INT_MAX);
7079 CHECK_TYPE_RANGED_INTEGER (int, sigcode);
7080 signo = XFIXNUM (sigcode);
7081 }
7082 else 7077 else
7083 { 7078 {
7084 char *name; 7079 char *name;
diff --git a/src/search.c b/src/search.c
index 7389fbef0ee..08b57c5faf3 100644
--- a/src/search.c
+++ b/src/search.c
@@ -2392,14 +2392,7 @@ since only regular expressions have distinguished subexpressions. */)
2392 if (num_regs <= 0) 2392 if (num_regs <= 0)
2393 error ("`replace-match' called before any match found"); 2393 error ("`replace-match' called before any match found");
2394 2394
2395 if (NILP (subexp)) 2395 sub = !NILP (subexp) ? check_integer_range (subexp, 0, num_regs - 1) : 0;
2396 sub = 0;
2397 else
2398 {
2399 CHECK_RANGED_INTEGER (subexp, 0, num_regs - 1);
2400 sub = XFIXNUM (subexp);
2401 }
2402
2403 ptrdiff_t sub_start = search_regs.start[sub]; 2396 ptrdiff_t sub_start = search_regs.start[sub];
2404 ptrdiff_t sub_end = search_regs.end[sub]; 2397 ptrdiff_t sub_end = search_regs.end[sub];
2405 eassert (sub_start <= sub_end); 2398 eassert (sub_start <= sub_end);
diff --git a/src/w32fns.c b/src/w32fns.c
index 2f01fb52e92..9bb4e27b018 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -1700,10 +1700,8 @@ w32_clear_under_internal_border (struct frame *f)
1700static void 1700static void
1701w32_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 1701w32_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1702{ 1702{
1703 int border; 1703 int argval = check_integer_range (arg, INT_MIN, INT_MAX);
1704 1704 int border = max (argval, 0);
1705 CHECK_TYPE_RANGED_INTEGER (int, arg);
1706 border = max (XFIXNUM (arg), 0);
1707 1705
1708 if (border != FRAME_INTERNAL_BORDER_WIDTH (f)) 1706 if (border != FRAME_INTERNAL_BORDER_WIDTH (f))
1709 { 1707 {
@@ -9203,8 +9201,8 @@ The coordinates X and Y are interpreted in pixels relative to a position
9203 UINT trail_num = 0; 9201 UINT trail_num = 0;
9204 BOOL ret = false; 9202 BOOL ret = false;
9205 9203
9206 CHECK_TYPE_RANGED_INTEGER (int, x); 9204 int xval = check_integer_range (x, INT_MIN, INT_MAX);
9207 CHECK_TYPE_RANGED_INTEGER (int, y); 9205 int yval = check_integer_range (y, INT_MIN, INT_MAX);
9208 9206
9209 block_input (); 9207 block_input ();
9210 /* When "mouse trails" are in effect, moving the mouse cursor 9208 /* When "mouse trails" are in effect, moving the mouse cursor
@@ -9213,7 +9211,7 @@ The coordinates X and Y are interpreted in pixels relative to a position
9213 if (os_subtype == OS_NT 9211 if (os_subtype == OS_NT
9214 && w32_major_version + w32_minor_version >= 6) 9212 && w32_major_version + w32_minor_version >= 6)
9215 ret = SystemParametersInfo (SPI_GETMOUSETRAILS, 0, &trail_num, 0); 9213 ret = SystemParametersInfo (SPI_GETMOUSETRAILS, 0, &trail_num, 0);
9216 SetCursorPos (XFIXNUM (x), XFIXNUM (y)); 9214 SetCursorPos (xval, yval);
9217 if (ret) 9215 if (ret)
9218 SystemParametersInfo (SPI_SETMOUSETRAILS, trail_num, NULL, 0); 9216 SystemParametersInfo (SPI_SETMOUSETRAILS, trail_num, NULL, 0);
9219 unblock_input (); 9217 unblock_input ();
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 *
diff --git a/src/xfns.c b/src/xfns.c
index 8de4c8bfd9e..ebe51b70a56 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1230,13 +1230,10 @@ x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1230 for (i = 0; i < mouse_cursor_max; i++) 1230 for (i = 0; i < mouse_cursor_max; i++)
1231 { 1231 {
1232 Lisp_Object shape_var = *mouse_cursor_types[i].shape_var_ptr; 1232 Lisp_Object shape_var = *mouse_cursor_types[i].shape_var_ptr;
1233 if (!NILP (shape_var)) 1233 cursor_data.cursor_num[i]
1234 { 1234 = (!NILP (shape_var)
1235 CHECK_TYPE_RANGED_INTEGER (unsigned, shape_var); 1235 ? check_uinteger_max (shape_var, UINT_MAX)
1236 cursor_data.cursor_num[i] = XFIXNUM (shape_var); 1236 : mouse_cursor_types[i].default_shape);
1237 }
1238 else
1239 cursor_data.cursor_num[i] = mouse_cursor_types[i].default_shape;
1240 } 1237 }
1241 1238
1242 block_input (); 1239 block_input ();
@@ -1801,10 +1798,7 @@ x_change_tool_bar_height (struct frame *f, int height)
1801static void 1798static void
1802x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval) 1799x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
1803{ 1800{
1804 int border; 1801 int border = check_int_nonnegative (arg);
1805
1806 CHECK_TYPE_RANGED_INTEGER (int, arg);
1807 border = max (XFIXNUM (arg), 0);
1808 1802
1809 if (border != FRAME_INTERNAL_BORDER_WIDTH (f)) 1803 if (border != FRAME_INTERNAL_BORDER_WIDTH (f))
1810 { 1804 {
@@ -3376,10 +3370,12 @@ x_icon (struct frame *f, Lisp_Object parms)
3376 = gui_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER); 3370 = gui_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
3377 Lisp_Object icon_y 3371 Lisp_Object icon_y
3378 = gui_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER); 3372 = gui_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
3373 int icon_xval, icon_yval;
3374
3379 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound)) 3375 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
3380 { 3376 {
3381 CHECK_TYPE_RANGED_INTEGER (int, icon_x); 3377 icon_xval = check_integer_range (icon_x, INT_MIN, INT_MAX);
3382 CHECK_TYPE_RANGED_INTEGER (int, icon_y); 3378 icon_yval = check_integer_range (icon_y, INT_MIN, INT_MAX);
3383 } 3379 }
3384 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) 3380 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
3385 error ("Both left and top icon corners of icon must be specified"); 3381 error ("Both left and top icon corners of icon must be specified");
@@ -3387,7 +3383,7 @@ x_icon (struct frame *f, Lisp_Object parms)
3387 block_input (); 3383 block_input ();
3388 3384
3389 if (! EQ (icon_x, Qunbound)) 3385 if (! EQ (icon_x, Qunbound))
3390 x_wm_set_icon_position (f, XFIXNUM (icon_x), XFIXNUM (icon_y)); 3386 x_wm_set_icon_position (f, icon_xval, icon_yval);
3391 3387
3392#if false /* gui_display_get_arg removes the visibility parameter as a 3388#if false /* gui_display_get_arg removes the visibility parameter as a
3393 side effect, but x_create_frame still needs it. */ 3389 side effect, but x_create_frame still needs it. */
@@ -5550,12 +5546,12 @@ The coordinates X and Y are interpreted in pixels relative to a position
5550 if (FRAME_INITIAL_P (f) || !FRAME_X_P (f)) 5546 if (FRAME_INITIAL_P (f) || !FRAME_X_P (f))
5551 return Qnil; 5547 return Qnil;
5552 5548
5553 CHECK_TYPE_RANGED_INTEGER (int, x); 5549 int xval = check_integer_range (x, INT_MIN, INT_MAX);
5554 CHECK_TYPE_RANGED_INTEGER (int, y); 5550 int yval = check_integer_range (y, INT_MIN, INT_MAX);
5555 5551
5556 block_input (); 5552 block_input ();
5557 XWarpPointer (FRAME_X_DISPLAY (f), None, DefaultRootWindow (FRAME_X_DISPLAY (f)), 5553 XWarpPointer (FRAME_X_DISPLAY (f), None, DefaultRootWindow (FRAME_X_DISPLAY (f)),
5558 0, 0, 0, 0, XFIXNUM (x), XFIXNUM (y)); 5554 0, 0, 0, 0, xval, yval);
5559 unblock_input (); 5555 unblock_input ();
5560 5556
5561 return Qnil; 5557 return Qnil;
diff --git a/src/xwidget.c b/src/xwidget.c
index ea8987f5b3b..0347f1e6483 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -750,11 +750,9 @@ DEFUN ("xwidget-resize", Fxwidget_resize, Sxwidget_resize, 3, 3, 0,
750 (Lisp_Object xwidget, Lisp_Object new_width, Lisp_Object new_height) 750 (Lisp_Object xwidget, Lisp_Object new_width, Lisp_Object new_height)
751{ 751{
752 CHECK_XWIDGET (xwidget); 752 CHECK_XWIDGET (xwidget);
753 CHECK_RANGED_INTEGER (new_width, 0, INT_MAX); 753 int w = check_integer_range (new_width, 0, INT_MAX);
754 CHECK_RANGED_INTEGER (new_height, 0, INT_MAX); 754 int h = check_integer_range (new_height, 0, INT_MAX);
755 struct xwidget *xw = XXWIDGET (xwidget); 755 struct xwidget *xw = XXWIDGET (xwidget);
756 int w = XFIXNAT (new_width);
757 int h = XFIXNAT (new_height);
758 756
759 xw->width = w; 757 xw->width = w;
760 xw->height = h; 758 xw->height = h;