diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2020-04-05 01:17:32 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2020-04-05 01:24:36 -0700 |
commit | bec5cfee7660f6e283efbd30a693a6f8e9ea46b8 (patch) | |
tree | b6b872dfb83579336e848a62f720b629426c0ac0 /src/bignum.c | |
parent | 9b8dacdb264412b919782920da916e306102262a (diff) | |
download | emacs-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/bignum.c')
-rw-r--r-- | src/bignum.c | 36 |
1 files changed, 36 insertions, 0 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) 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; +} |