summaryrefslogtreecommitdiff
path: root/src/frame.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2020-04-05 01:17:32 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2020-04-05 01:24:36 -0700
commitbec5cfee7660f6e283efbd30a693a6f8e9ea46b8 (patch)
treeb6b872dfb83579336e848a62f720b629426c0ac0 /src/frame.c
parent9b8dacdb264412b919782920da916e306102262a (diff)
downloademacs-bec5cfee7660f6e283efbd30a693a6f8e9ea46b8.tar.gz
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/frame.c')
-rw-r--r--src/frame.c99
1 files changed, 43 insertions, 56 deletions
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.
(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;
}