diff options
| author | Paul Eggert | 2020-04-05 01:17:32 -0700 |
|---|---|---|
| committer | Paul Eggert | 2020-04-05 01:24:36 -0700 |
| commit | bec5cfee7660f6e283efbd30a693a6f8e9ea46b8 (patch) | |
| tree | b6b872dfb83579336e848a62f720b629426c0ac0 /src/bignum.c | |
| parent | 9b8dacdb264412b919782920da916e306102262a (diff) | |
| download | emacs-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/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) | |||
| 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 | |||
| 438 | intmax_t | ||
| 439 | check_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 | |||
| 451 | uintmax_t | ||
| 452 | check_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 | |||
| 464 | int | ||
| 465 | check_int_nonnegative (Lisp_Object x) | ||
| 466 | { | ||
| 467 | CHECK_INTEGER (x); | ||
| 468 | return Fnatnump (x) ? check_integer_range (x, 0, INT_MAX) : 0; | ||
| 469 | } | ||