diff options
| author | Paul Eggert | 2019-08-15 02:18:06 -0700 |
|---|---|---|
| committer | Paul Eggert | 2019-08-15 02:18:44 -0700 |
| commit | 3548fd8a53869ce6b42c47f690660cb8eddb8aab (patch) | |
| tree | 4da084bfab97e61c649abb3332254d0ea898188f /src/fns.c | |
| parent | 6cbf73b5f9f51b5e25b855bf9f521c1ef070dd4a (diff) | |
| download | emacs-3548fd8a53869ce6b42c47f690660cb8eddb8aab.tar.gz emacs-3548fd8a53869ce6b42c47f690660cb8eddb8aab.zip | |
Debug out-of-range make_fixnum args
With --enable-checking, make_fixnum (N) now checks that N is
in fixnum range. Suggested by Pip Cet in:
https://lists.gnu.org/r/emacs-devel/2019-07/msg00548.html
A new function make_ufixnum (N) is for the rare cases where N
is intended to be unsigned and is in the range 0..INTMASK.
* configure.ac (AC_C_TYPEOF): Add.
(HAVE_STATEMENT_EXPRESSIONS): Resurrect this macro.
* src/fns.c (Frandom, hashfn_eq, hashfn_equal, hashfn_user_defined):
* src/profiler.c (hashfn_profiler):
Use make_ufixnum rather than make_fixum, since the argument is
an unsigned integer in the range 0..INTMASK rather than a signed
integer in the range MOST_NEGATIVE_FIXNUM..MOST_POSITIVE_FIXNUM.
Typically this is for hashes.
* src/lisp.h (lisp_h_make_fixnum_wrap) [USE_LSB_TAG]:
Rename from lisp_h_make_fixnum.
(lisp_h_make_fixnum): Redefine in terms of lisp_h_make_fixnum_wrap.
Check for fixnum overflow on compilers like GCC that
have statement expressions and typeof.
(FIXNUM_OVERFLOW_P): Move up.
(make_fixnum): Check for fixnum overflow.
(make_ufixnum): New function, which checks that the arg
fits into 0..INTMASK range.
Diffstat (limited to 'src/fns.c')
| -rw-r--r-- | src/fns.c | 8 |
1 files changed, 4 insertions, 4 deletions
| @@ -87,7 +87,7 @@ See Info node `(elisp)Random Numbers' for more details. */) | |||
| 87 | return make_fixnum (remainder); | 87 | return make_fixnum (remainder); |
| 88 | val = get_random (); | 88 | val = get_random (); |
| 89 | } | 89 | } |
| 90 | return make_fixnum (val); | 90 | return make_ufixnum (val); |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | /* Random data-structure functions. */ | 93 | /* Random data-structure functions. */ |
| @@ -3994,7 +3994,7 @@ cmpfn_user_defined (Lisp_Object key1, Lisp_Object key2, | |||
| 3994 | static Lisp_Object | 3994 | static Lisp_Object |
| 3995 | hashfn_eq (Lisp_Object key, struct Lisp_Hash_Table *h) | 3995 | hashfn_eq (Lisp_Object key, struct Lisp_Hash_Table *h) |
| 3996 | { | 3996 | { |
| 3997 | return make_fixnum (XHASH (key) ^ XTYPE (key)); | 3997 | return make_ufixnum (XHASH (key) ^ XTYPE (key)); |
| 3998 | } | 3998 | } |
| 3999 | 3999 | ||
| 4000 | /* Ignore HT and return a hash code for KEY which uses 'equal' to compare keys. | 4000 | /* Ignore HT and return a hash code for KEY which uses 'equal' to compare keys. |
| @@ -4003,7 +4003,7 @@ hashfn_eq (Lisp_Object key, struct Lisp_Hash_Table *h) | |||
| 4003 | Lisp_Object | 4003 | Lisp_Object |
| 4004 | hashfn_equal (Lisp_Object key, struct Lisp_Hash_Table *h) | 4004 | hashfn_equal (Lisp_Object key, struct Lisp_Hash_Table *h) |
| 4005 | { | 4005 | { |
| 4006 | return make_fixnum (sxhash (key, 0)); | 4006 | return make_ufixnum (sxhash (key, 0)); |
| 4007 | } | 4007 | } |
| 4008 | 4008 | ||
| 4009 | /* Ignore HT and return a hash code for KEY which uses 'eql' to compare keys. | 4009 | /* Ignore HT and return a hash code for KEY which uses 'eql' to compare keys. |
| @@ -4023,7 +4023,7 @@ hashfn_user_defined (Lisp_Object key, struct Lisp_Hash_Table *h) | |||
| 4023 | { | 4023 | { |
| 4024 | Lisp_Object args[] = { h->test.user_hash_function, key }; | 4024 | Lisp_Object args[] = { h->test.user_hash_function, key }; |
| 4025 | Lisp_Object hash = hash_table_user_defined_call (ARRAYELTS (args), args, h); | 4025 | Lisp_Object hash = hash_table_user_defined_call (ARRAYELTS (args), args, h); |
| 4026 | return FIXNUMP (hash) ? hash : make_fixnum (sxhash (hash, 0)); | 4026 | return FIXNUMP (hash) ? hash : make_ufixnum (sxhash (hash, 0)); |
| 4027 | } | 4027 | } |
| 4028 | 4028 | ||
| 4029 | struct hash_table_test const | 4029 | struct hash_table_test const |