Commit bec5cfee authored by Paul Eggert's avatar Paul Eggert

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.
parent 9b8dacdb
Pipeline #5174 passed with stage
in 67 minutes and 22 seconds
......@@ -431,3 +431,39 @@ make_bignum_str (char const *num, int base)
eassert (check == 0);
return make_lisp_ptr (b, Lisp_Vectorlike);
}
/* Check that X is a Lisp integer in the range LO..HI.
Return X's value as an intmax_t. */
intmax_t
check_integer_range (Lisp_Object x, intmax_t lo, intmax_t hi)
{
CHECK_INTEGER (x);
intmax_t i;
if (! (integer_to_intmax (x, &i) && lo <= i && i <= hi))
args_out_of_range_3 (x, make_int (lo), make_int (hi));
return i;
}
/* Check that X is a Lisp integer in the range 0..HI.
Return X's value as an uintmax_t. */
uintmax_t
check_uinteger_max (Lisp_Object x, uintmax_t hi)
{
CHECK_INTEGER (x);
uintmax_t i;
if (! (integer_to_uintmax (x, &i) && i <= hi))
args_out_of_range_3 (x, make_fixnum (0), make_uint (hi));
return i;
}
/* Check that X is a Lisp integer no greater than INT_MAX,
and return its value or zero, whichever is greater. */
int
check_int_nonnegative (Lisp_Object x)
{
CHECK_INTEGER (x);
return Fnatnump (x) ? check_integer_range (x, 0, INT_MAX) : 0;
}
......@@ -876,10 +876,7 @@ usage: (unibyte-string &rest BYTES) */)
Lisp_Object str = make_uninit_string (n);
unsigned char *p = SDATA (str);
for (ptrdiff_t i = 0; i < n; i++)
{
CHECK_RANGED_INTEGER (args[i], 0, 255);
*p++ = XFIXNUM (args[i]);
}
*p++ = check_integer_range (args[i], 0, 255);
return str;
}
......
......@@ -866,15 +866,10 @@ usage: (define-charset-internal ...) */)
val = args[charset_arg_code_space];
for (i = 0, dimension = 0, nchars = 1; ; i++)
{
Lisp_Object min_byte_obj, max_byte_obj;
int min_byte, max_byte;
min_byte_obj = Faref (val, make_fixnum (i * 2));
max_byte_obj = Faref (val, make_fixnum (i * 2 + 1));
CHECK_RANGED_INTEGER (min_byte_obj, 0, 255);
min_byte = XFIXNUM (min_byte_obj);
CHECK_RANGED_INTEGER (max_byte_obj, min_byte, 255);
max_byte = XFIXNUM (max_byte_obj);
Lisp_Object min_byte_obj = Faref (val, make_fixnum (i * 2));
Lisp_Object max_byte_obj = Faref (val, make_fixnum (i * 2 + 1));
int min_byte = check_integer_range (min_byte_obj, 0, 255);
int max_byte = check_integer_range (max_byte_obj, min_byte, 255);
charset.code_space[i * 4] = min_byte;
charset.code_space[i * 4 + 1] = max_byte;
charset.code_space[i * 4 + 2] = max_byte - min_byte + 1;
......@@ -887,13 +882,8 @@ usage: (define-charset-internal ...) */)
}
val = args[charset_arg_dimension];
if (NILP (val))
charset.dimension = dimension;
else
{
CHECK_RANGED_INTEGER (val, 1, 4);
charset.dimension = XFIXNUM (val);
}
charset.dimension
= !NILP (val) ? check_integer_range (val, 1, 4) : dimension;
charset.code_linear_p
= (charset.dimension == 1
......@@ -979,13 +969,7 @@ usage: (define-charset-internal ...) */)
}
val = args[charset_arg_iso_revision];
if (NILP (val))
charset.iso_revision = -1;
else
{
CHECK_RANGED_INTEGER (val, -1, 63);
charset.iso_revision = XFIXNUM (val);
}
charset.iso_revision = !NILP (val) ? check_integer_range (val, -1, 63) : -1;
val = args[charset_arg_emacs_mule_id];
if (NILP (val))
......@@ -1090,8 +1074,7 @@ usage: (define-charset-internal ...) */)
car_part = XCAR (elt);
cdr_part = XCDR (elt);
CHECK_CHARSET_GET_ID (car_part, this_id);
CHECK_TYPE_RANGED_INTEGER (int, cdr_part);
offset = XFIXNUM (cdr_part);
offset = check_integer_range (cdr_part, INT_MIN, INT_MAX);
}
else
{
......
......@@ -11061,10 +11061,8 @@ usage: (define-coding-system-internal ...) */)
else
{
CHECK_CONS (val);
CHECK_RANGED_INTEGER (XCAR (val), 0, 255);
from = XFIXNUM (XCAR (val));
CHECK_RANGED_INTEGER (XCDR (val), from, 255);
to = XFIXNUM (XCDR (val));
from = check_integer_range (XCAR (val), 0, 255);
to = check_integer_range (XCDR (val), from, 255);
}
for (int i = from; i <= to; i++)
SSET (valids, i, 1);
......@@ -11149,7 +11147,7 @@ usage: (define-coding-system-internal ...) */)
val = XCAR (tail);
CHECK_CONS (val);
CHECK_CHARSET_GET_ID (XCAR (val), id);
CHECK_RANGED_INTEGER (XCDR (val), 0, 3);
check_integer_range (XCDR (val), 0, 3);
XSETCAR (val, make_fixnum (id));
}
......
......@@ -5682,8 +5682,8 @@ in `current-time' or an integer flag as returned by `visited-file-modtime'. */)
struct timespec mtime;
if (FIXNUMP (time_flag))
{
CHECK_RANGED_INTEGER (time_flag, -1, 0);
mtime = make_timespec (0, UNKNOWN_MODTIME_NSECS - XFIXNUM (time_flag));
int flag = check_integer_range (time_flag, -1, 0);
mtime = make_timespec (0, UNKNOWN_MODTIME_NSECS - flag);
}
else
mtime = lisp_time_argument (time_flag);
......
......@@ -2558,26 +2558,26 @@ before calling this function on it, like this.
(Lisp_Object frame, Lisp_Object x, Lisp_Object y)
{
CHECK_LIVE_FRAME (frame);
CHECK_TYPE_RANGED_INTEGER (int, x);
CHECK_TYPE_RANGED_INTEGER (int, y);
int xval = check_integer_range (x, INT_MIN, INT_MAX);
int yval = check_integer_range (y, INT_MIN, INT_MAX);
/* I think this should be done with a hook. */
#ifdef HAVE_WINDOW_SYSTEM
if (FRAME_WINDOW_P (XFRAME (frame)))
/* Warping the mouse will cause enternotify and focus events. */
frame_set_mouse_position (XFRAME (frame), XFIXNUM (x), XFIXNUM (y));
frame_set_mouse_position (XFRAME (frame), xval, yval);
#else
#if defined (MSDOS)
if (FRAME_MSDOS_P (XFRAME (frame)))
{
Fselect_frame (frame, Qnil);
mouse_moveto (XFIXNUM (x), XFIXNUM (y));
mouse_moveto (xval, yval);
}
#else
#ifdef HAVE_GPM
{
Fselect_frame (frame, Qnil);
term_mouse_moveto (XFIXNUM (x), XFIXNUM (y));
term_mouse_moveto (xval, yval);
}
#endif
#endif
......@@ -2599,26 +2599,26 @@ before calling this function on it, like this.
(Lisp_Object frame, Lisp_Object x, Lisp_Object y)
{
CHECK_LIVE_FRAME (frame);
CHECK_TYPE_RANGED_INTEGER (int, x);
CHECK_TYPE_RANGED_INTEGER (int, y);
int xval = check_integer_range (x, INT_MIN, INT_MAX);
int yval = check_integer_range (y, INT_MIN, INT_MAX);
/* I think this should be done with a hook. */
#ifdef HAVE_WINDOW_SYSTEM
if (FRAME_WINDOW_P (XFRAME (frame)))
/* Warping the mouse will cause enternotify and focus events. */
frame_set_mouse_pixel_position (XFRAME (frame), XFIXNUM (x), XFIXNUM (y));
frame_set_mouse_pixel_position (XFRAME (frame), xval, yval);
#else
#if defined (MSDOS)
if (FRAME_MSDOS_P (XFRAME (frame)))
{
Fselect_frame (frame, Qnil);
mouse_moveto (XFIXNUM (x), XFIXNUM (y));
mouse_moveto (xval, yval);
}
#else
#ifdef HAVE_GPM
{
Fselect_frame (frame, Qnil);
term_mouse_moveto (XFIXNUM (x), XFIXNUM (y));
term_mouse_moveto (xval, yval);
}
#endif
#endif
......@@ -3545,6 +3545,21 @@ DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_widt
return make_fixnum (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
}
static int
check_frame_pixels (Lisp_Object size, Lisp_Object pixelwise, int item_size)
{
CHECK_INTEGER (size);
if (!NILP (pixelwise))
item_size = 1;
intmax_t sz;
int pixel_size; /* size * item_size */
if (! integer_to_intmax (size, &sz)
|| INT_MULTIPLY_WRAPV (sz, item_size, &pixel_size))
args_out_of_range_3 (size, make_int (INT_MIN / item_size),
make_int (INT_MAX / item_size));
return pixel_size;
}
DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4,
"(list (selected-frame) (prefix-numeric-value current-prefix-arg))",
doc: /* Set text height of frame FRAME to HEIGHT lines.
......@@ -3562,15 +3577,9 @@ currently selected frame will be set to this height. */)
(Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
{
struct frame *f = decode_live_frame (frame);
int pixel_height;
CHECK_TYPE_RANGED_INTEGER (int, height);
pixel_height = (!NILP (pixelwise)
? XFIXNUM (height)
: XFIXNUM (height) * FRAME_LINE_HEIGHT (f));
int pixel_height = check_frame_pixels (height, pixelwise,
FRAME_LINE_HEIGHT (f));
adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
return Qnil;
}
......@@ -3591,15 +3600,9 @@ currently selected frame will be set to this width. */)
(Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
{
struct frame *f = decode_live_frame (frame);
int pixel_width;
CHECK_TYPE_RANGED_INTEGER (int, width);
pixel_width = (!NILP (pixelwise)
? XFIXNUM (width)
: XFIXNUM (width) * FRAME_COLUMN_WIDTH (f));
int pixel_width = check_frame_pixels (width, pixelwise,
FRAME_COLUMN_WIDTH (f));
adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
return Qnil;
}
......@@ -3613,19 +3616,11 @@ font height. */)
(Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
{
struct frame *f = decode_live_frame (frame);
int pixel_width, pixel_height;
CHECK_TYPE_RANGED_INTEGER (int, width);
CHECK_TYPE_RANGED_INTEGER (int, height);
pixel_width = (!NILP (pixelwise)
? XFIXNUM (width)
: XFIXNUM (width) * FRAME_COLUMN_WIDTH (f));
pixel_height = (!NILP (pixelwise)
? XFIXNUM (height)
: XFIXNUM (height) * FRAME_LINE_HEIGHT (f));
int pixel_width = check_frame_pixels (width, pixelwise,
FRAME_COLUMN_WIDTH (f));
int pixel_height = check_frame_pixels (height, pixelwise,
FRAME_LINE_HEIGHT (f));
adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
return Qnil;
}
......@@ -3655,18 +3650,14 @@ bottom edge of FRAME's display. */)
(Lisp_Object frame, Lisp_Object x, Lisp_Object y)
{
struct frame *f = decode_live_frame (frame);
CHECK_TYPE_RANGED_INTEGER (int, x);
CHECK_TYPE_RANGED_INTEGER (int, y);
int xval = check_integer_range (x, INT_MIN, INT_MAX);
int yval = check_integer_range (y, INT_MIN, INT_MAX);
if (FRAME_WINDOW_P (f))
{
#ifdef HAVE_WINDOW_SYSTEM
if (FRAME_TERMINAL (f)->set_frame_offset_hook)
FRAME_TERMINAL (f)->set_frame_offset_hook (f,
XFIXNUM (x),
XFIXNUM (y),
1);
FRAME_TERMINAL (f)->set_frame_offset_hook (f, xval, yval, 1);
#endif
}
......@@ -4641,23 +4632,22 @@ gui_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_va
void
gui_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
CHECK_TYPE_RANGED_INTEGER (int, arg);
int border_width = check_integer_range (arg, INT_MIN, INT_MAX);
if (XFIXNUM (arg) == f->border_width)
if (border_width == f->border_width)
return;
if (FRAME_NATIVE_WINDOW (f) != 0)
error ("Cannot change the border width of a frame");
f->border_width = XFIXNUM (arg);
f->border_width = border_width;
}
void
gui_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
CHECK_TYPE_RANGED_INTEGER (int, arg);
int new = max (0, XFIXNUM (arg));
int new = check_int_nonnegative (arg);
if (new != old)
{
f->right_divider_width = new;
......@@ -4671,8 +4661,7 @@ void
gui_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
CHECK_TYPE_RANGED_INTEGER (int, arg);
int new = max (0, XFIXNUM (arg));
int new = check_int_nonnegative (arg);
if (new != old)
{
f->bottom_divider_width = new;
......@@ -5651,8 +5640,7 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p,
f->top_pos = 0;
else
{
CHECK_TYPE_RANGED_INTEGER (int, top);
f->top_pos = XFIXNUM (top);
f->top_pos = check_integer_range (top, INT_MIN, INT_MAX);
if (f->top_pos < 0)
window_prompting |= YNegative;
}
......@@ -5682,8 +5670,7 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p,
f->left_pos = 0;
else
{
CHECK_TYPE_RANGED_INTEGER (int, left);
f->left_pos = XFIXNUM (left);
f->left_pos = check_integer_range (left, INT_MIN, INT_MAX);
if (f->left_pos < 0)
window_prompting |= XNegative;
}
......
......@@ -254,8 +254,7 @@ parse_viewing_conditions (Lisp_Object view, const cmsCIEXYZ *wp,
#define PARSE_VIEW_CONDITION_INT(field) \
if (CONSP (view) && FIXNATP (XCAR (view))) \
{ \
CHECK_RANGED_INTEGER (XCAR (view), 1, 4); \
vc->field = XFIXNUM (XCAR (view)); \
vc->field = check_integer_range (XCAR (view), 1, 4); \
view = XCDR (view); \
} \
else \
......
......@@ -589,15 +589,19 @@ INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t,
Lisp_Object);
/* Defined in bignum.c. */
extern int check_int_nonnegative (Lisp_Object);
extern intmax_t check_integer_range (Lisp_Object, intmax_t, intmax_t);
extern double bignum_to_double (Lisp_Object) ATTRIBUTE_CONST;
extern Lisp_Object make_bigint (intmax_t);
extern Lisp_Object make_biguint (uintmax_t);
extern uintmax_t check_uinteger_max (Lisp_Object, uintmax_t);
/* Defined in chartab.c. */
extern Lisp_Object char_table_ref (Lisp_Object, int);
extern void char_table_set (Lisp_Object, int, Lisp_Object);
/* Defined in data.c. */
extern AVOID args_out_of_range_3 (Lisp_Object, Lisp_Object, Lisp_Object);
extern AVOID wrong_type_argument (Lisp_Object, Lisp_Object);
extern Lisp_Object default_value (Lisp_Object symbol);
......@@ -3002,20 +3006,6 @@ CHECK_FIXNAT (Lisp_Object x)
CHECK_TYPE (FIXNATP (x), Qwholenump, x);
}
#define CHECK_RANGED_INTEGER(x, lo, hi) \
do { \
CHECK_FIXNUM (x); \
if (! ((lo) <= XFIXNUM (x) && XFIXNUM (x) <= (hi))) \
args_out_of_range_3 (x, INT_TO_INTEGER (lo), INT_TO_INTEGER (hi)); \
} while (false)
#define CHECK_TYPE_RANGED_INTEGER(type, x) \
do { \
if (TYPE_SIGNED (type)) \
CHECK_RANGED_INTEGER (x, TYPE_MINIMUM (type), TYPE_MAXIMUM (type)); \
else \
CHECK_RANGED_INTEGER (x, 0, TYPE_MAXIMUM (type)); \
} while (false)
INLINE double
XFLOATINT (Lisp_Object n)
{
......@@ -3581,7 +3571,6 @@ extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t);
extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *);
extern AVOID args_out_of_range (Lisp_Object, Lisp_Object);
extern AVOID args_out_of_range_3 (Lisp_Object, Lisp_Object, Lisp_Object);
extern AVOID circular_list (Lisp_Object);
extern Lisp_Object do_symval_forwarding (lispfwd);
enum Set_Internal_Bind {
......
......@@ -1253,18 +1253,16 @@ x_popup_menu_1 (Lisp_Object position, Lisp_Object menu)
but I don't want to make one now. */
CHECK_WINDOW (window);
CHECK_RANGED_INTEGER (x,
(xpos < INT_MIN - MOST_NEGATIVE_FIXNUM
? (EMACS_INT) INT_MIN - xpos
: MOST_NEGATIVE_FIXNUM),
INT_MAX - xpos);
CHECK_RANGED_INTEGER (y,
(ypos < INT_MIN - MOST_NEGATIVE_FIXNUM
? (EMACS_INT) INT_MIN - ypos
: MOST_NEGATIVE_FIXNUM),
INT_MAX - ypos);
xpos += XFIXNUM (x);
ypos += XFIXNUM (y);
xpos += check_integer_range (x,
(xpos < INT_MIN - MOST_NEGATIVE_FIXNUM
? (EMACS_INT) INT_MIN - xpos
: MOST_NEGATIVE_FIXNUM),
INT_MAX - xpos);
ypos += check_integer_range (y,
(ypos < INT_MIN - MOST_NEGATIVE_FIXNUM
? (EMACS_INT) INT_MIN - ypos
: MOST_NEGATIVE_FIXNUM),
INT_MAX - ypos);
XSETFRAME (Vmenu_updating_frame, f);
}
......
......@@ -706,14 +706,11 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
ns_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
int old_width = FRAME_INTERNAL_BORDER_WIDTH (f);
int new_width = check_int_nonnegative (arg);
CHECK_TYPE_RANGED_INTEGER (int, arg);
f->internal_border_width = XFIXNUM (arg);
if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
f->internal_border_width = 0;
if (FRAME_INTERNAL_BORDER_WIDTH (f) == old_width)
if (new_width == old_width)
return;
f->internal_border_width = new_width;
if (FRAME_NATIVE_WINDOW (f) != 0)
adjust_frame_size (f, -1, -1, 3, 0, Qinternal_border_width);
......@@ -2956,16 +2953,16 @@ value is a list of the form (LEFT, TOP, RIGHT, BOTTOM). All values are
if (FRAME_INITIAL_P (f) || !FRAME_NS_P (f))
return Qnil;
CHECK_TYPE_RANGED_INTEGER (int, x);
CHECK_TYPE_RANGED_INTEGER (int, y);
int xval = check_integer_range (x, INT_MIN, INT_MAX);
int yval = check_integer_range (y, INT_MIN, INT_MAX);
mouse_x = screen_frame.origin.x + XFIXNUM (x);
mouse_x = screen_frame.origin.x + xval;
if (screen == primary_screen)
mouse_y = screen_frame.origin.y + XFIXNUM (y);
mouse_y = screen_frame.origin.y + yval;
else
mouse_y = (primary_screen_height - screen_frame.size.height
- screen_frame.origin.y) + XFIXNUM (y);
- screen_frame.origin.y) + yval;
CGPoint mouse_pos = CGPointMake(mouse_x, mouse_y);
CGWarpMouseCursorPosition (mouse_pos);
......
......@@ -1392,14 +1392,12 @@ nil otherwise. */)
CHECK_PROCESS (process);
/* All known platforms store window sizes as 'unsigned short'. */
CHECK_RANGED_INTEGER (height, 0, USHRT_MAX);
CHECK_RANGED_INTEGER (width, 0, USHRT_MAX);
unsigned short h = check_uinteger_max (height, USHRT_MAX);
unsigned short w = check_uinteger_max (width, USHRT_MAX);
if (NETCONN_P (process)
|| XPROCESS (process)->infd < 0
|| (set_window_size (XPROCESS (process)->infd,
XFIXNUM (height), XFIXNUM (width))
< 0))
|| set_window_size (XPROCESS (process)->infd, h, w) < 0)
return Qnil;
else
return Qt;
......@@ -7075,10 +7073,7 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
}
if (FIXNUMP (sigcode))
{
CHECK_TYPE_RANGED_INTEGER (int, sigcode);
signo = XFIXNUM (sigcode);
}
signo = check_integer_range (sigcode, INT_MIN, INT_MAX);
else
{
char *name;
......
......@@ -2392,14 +2392,7 @@ since only regular expressions have distinguished subexpressions. */)
if (num_regs <= 0)
error ("`replace-match' called before any match found");
if (NILP (subexp))
sub = 0;
else
{
CHECK_RANGED_INTEGER (subexp, 0, num_regs - 1);
sub = XFIXNUM (subexp);
}
sub = !NILP (subexp) ? check_integer_range (subexp, 0, num_regs - 1) : 0;
ptrdiff_t sub_start = search_regs.start[sub];
ptrdiff_t sub_end = search_regs.end[sub];
eassert (sub_start <= sub_end);
......
......@@ -1700,10 +1700,8 @@ w32_clear_under_internal_border (struct frame *f)
static void
w32_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
int border;
CHECK_TYPE_RANGED_INTEGER (int, arg);
border = max (XFIXNUM (arg), 0);
int argval = check_integer_range (arg, INT_MIN, INT_MAX);
int border = max (argval, 0);
if (border != FRAME_INTERNAL_BORDER_WIDTH (f))
{
......@@ -9203,8 +9201,8 @@ The coordinates X and Y are interpreted in pixels relative to a position
UINT trail_num = 0;
BOOL ret = false;
CHECK_TYPE_RANGED_INTEGER (int, x);
CHECK_TYPE_RANGED_INTEGER (int, y);
int xval = check_integer_range (x, INT_MIN, INT_MAX);
int yval = check_integer_range (y, INT_MIN, INT_MAX);
block_input ();
/* 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
if (os_subtype == OS_NT
&& w32_major_version + w32_minor_version >= 6)
ret = SystemParametersInfo (SPI_GETMOUSETRAILS, 0, &trail_num, 0);
SetCursorPos (XFIXNUM (x), XFIXNUM (y));
SetCursorPos (xval, yval);
if (ret)
SystemParametersInfo (SPI_SETMOUSETRAILS, trail_num, NULL, 0);
unblock_input ();
......
......@@ -2108,30 +2108,20 @@ though when run from an idle timer with a delay of zero seconds. */)
|| window_outdated (w))
return Qnil;
if (NILP (first))
row = (NILP (body)
? MATRIX_ROW (w->current_matrix, 0)
: MATRIX_FIRST_TEXT_ROW (w->current_matrix));
else if (FIXNUMP (first))
{
CHECK_RANGED_INTEGER (first, 0, w->current_matrix->nrows);
row = MATRIX_ROW (w->current_matrix, XFIXNUM (first));
}
else
error ("Invalid specification of first line");
if (NILP (last))
end_row = (NILP (body)
? MATRIX_ROW (w->current_matrix, w->current_matrix->nrows)
: MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w));
else if (FIXNUMP (last))
{
CHECK_RANGED_INTEGER (last, 0, w->current_matrix->nrows);
end_row = MATRIX_ROW (w->current_matrix, XFIXNUM (last));
}
else
error ("Invalid specification of last line");
row = (!NILP (first)
? MATRIX_ROW (w->current_matrix,
check_integer_range (first, 0,
w->current_matrix->nrows))
: NILP (body)
? MATRIX_ROW (w->current_matrix, 0)
: MATRIX_FIRST_TEXT_ROW (w->current_matrix));
end_row = (!NILP (last)
? MATRIX_ROW (w->current_matrix,
check_integer_range (last, 0,
w->current_matrix->nrows))
: NILP (body)
? MATRIX_ROW (w->current_matrix, w->current_matrix->nrows)
: MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w));
while (row <= end_row && row->enabled_p
&& row->y + row->height < max_y)
......@@ -4325,11 +4315,11 @@ Note: This function does not operate on any child windows of WINDOW. */)
EMACS_INT size_min = NILP (add) ? 0 : - XFIXNUM (w->new_pixel);
EMACS_INT size_max = size_min + min (INT_MAX, MOST_POSITIVE_FIXNUM);
CHECK_RANGED_INTEGER (size, size_min, size_max);
int checked_size = check_integer_range (size, size_min, size_max);
if (NILP (add))
wset_new_pixel (w, size);
else
wset_new_pixel (w, make_fixnum (XFIXNUM (w->new_pixel) + XFIXNUM (size)));
wset_new_pixel (w, make_fixnum (XFIXNUM (w->new_pixel) + checked_size));
return w->new_pixel;
}
......@@ -7506,8 +7496,7 @@ extract_dimension (Lisp_Object dimension)
{
if (NILP (dimension))
return -1;
CHECK_RANGED_INTEGER (dimension, 0, INT_MAX);
return XFIXNUM (dimension);
return check_integer_range (dimension, 0, INT_MAX);
}
static struct window *
......
......@@ -1230,13 +1230,10 @@ x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
for (i = 0; i < mouse_cursor_max; i++)
{
Lisp_Object shape_var = *mouse_cursor_types[i].shape_var_ptr;
if (!NILP (shape_var))
{
CHECK_TYPE_RANGED_INTEGER (unsigned, shape_var);
cursor_data.cursor_num[i] = XFIXNUM (shape_var);
}
else
cursor_data.cursor_num[i] = mouse_cursor_types[i].default_shape;
cursor_data.cursor_num[i]
= (!NILP (shape_var)
? check_uinteger_max (shape_var, UINT_MAX)
: mouse_cursor_types[i].default_shape);
}
block_input ();
......@@ -1801,10 +1798,7 @@ x_change_tool_bar_height (struct frame *f, int height)
static void
x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
{
int border;
CHECK_TYPE_RANGED_INTEGER (int, arg);
border = max (XFIXNUM (arg), 0);
int border = check_int_nonnegative (arg);
if (border != FRAME_INTERNAL_BORDER_WIDTH (f))
{
......@@ -3376,10 +3370,12 @@ x_icon (struct frame *f, Lisp_Object parms)
= gui_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);