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/lisp.h | |
| 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/lisp.h')
| -rw-r--r-- | src/lisp.h | 19 |
1 files changed, 4 insertions, 15 deletions
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. */ |
| 592 | extern int check_int_nonnegative (Lisp_Object); | ||
| 593 | extern intmax_t check_integer_range (Lisp_Object, intmax_t, intmax_t); | ||
| 592 | extern double bignum_to_double (Lisp_Object) ATTRIBUTE_CONST; | 594 | extern double bignum_to_double (Lisp_Object) ATTRIBUTE_CONST; |
| 593 | extern Lisp_Object make_bigint (intmax_t); | 595 | extern Lisp_Object make_bigint (intmax_t); |
| 594 | extern Lisp_Object make_biguint (uintmax_t); | 596 | extern Lisp_Object make_biguint (uintmax_t); |
| 597 | extern uintmax_t check_uinteger_max (Lisp_Object, uintmax_t); | ||
| 595 | 598 | ||
| 596 | /* Defined in chartab.c. */ | 599 | /* Defined in chartab.c. */ |
| 597 | extern Lisp_Object char_table_ref (Lisp_Object, int); | 600 | extern Lisp_Object char_table_ref (Lisp_Object, int); |
| 598 | extern void char_table_set (Lisp_Object, int, Lisp_Object); | 601 | extern void char_table_set (Lisp_Object, int, Lisp_Object); |
| 599 | 602 | ||
| 600 | /* Defined in data.c. */ | 603 | /* Defined in data.c. */ |
| 604 | extern AVOID args_out_of_range_3 (Lisp_Object, Lisp_Object, Lisp_Object); | ||
| 601 | extern AVOID wrong_type_argument (Lisp_Object, Lisp_Object); | 605 | extern AVOID wrong_type_argument (Lisp_Object, Lisp_Object); |
| 602 | extern Lisp_Object default_value (Lisp_Object symbol); | 606 | extern 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 | |||
| 3019 | INLINE double | 3009 | INLINE double |
| 3020 | XFLOATINT (Lisp_Object n) | 3010 | XFLOATINT (Lisp_Object n) |
| 3021 | { | 3011 | { |
| @@ -3581,7 +3571,6 @@ extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t); | |||
| 3581 | 3571 | ||
| 3582 | extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *); | 3572 | extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *); |
| 3583 | extern AVOID args_out_of_range (Lisp_Object, Lisp_Object); | 3573 | extern AVOID args_out_of_range (Lisp_Object, Lisp_Object); |
| 3584 | extern AVOID args_out_of_range_3 (Lisp_Object, Lisp_Object, Lisp_Object); | ||
| 3585 | extern AVOID circular_list (Lisp_Object); | 3574 | extern AVOID circular_list (Lisp_Object); |
| 3586 | extern Lisp_Object do_symval_forwarding (lispfwd); | 3575 | extern Lisp_Object do_symval_forwarding (lispfwd); |
| 3587 | enum Set_Internal_Bind { | 3576 | enum Set_Internal_Bind { |