diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2016-09-24 02:35:13 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2016-09-24 02:35:29 -0700 |
commit | b3e1b382456b0f7d108c57d6f902bbddfdd97b2a (patch) | |
tree | aa3bcb76dfb30dace2811de0612a569daf250d8d /src/lread.c | |
parent | 4f05e930ca9ca4fa87aa2bc83187590432d792bd (diff) | |
download | emacs-b3e1b382456b0f7d108c57d6f902bbddfdd97b2a.tar.gz |
Improve integer overflow handling a bit
* src/charset.c (read_hex): Use INT_LEFT_SHIFT_OVERFLOW for clarity.
The machine code is the same on my platform.
* src/doprnt.c (doprnt):
* src/emacs-module.c (module_funcall):
* src/font.c (font_intern_prop):
* src/keyboard.c (Frecursion_depth):
* src/lread.c (read1):
Use WRAPV macros instead of checking overflow by hand.
* src/editfns.c (hi_time, time_arith, decode_time_components):
* src/emacs-module.c (Fmodule_load):
Simplify by using FIXNUM_OVERFLOW_P.
* src/emacs-module.c: Include intprops.h.
* src/xdisp.c (percent99): New function.
(decode_mode_spec): Use it to simplify overflow avoidance and
formatting of %p and %P.
Diffstat (limited to 'src/lread.c')
-rw-r--r-- | src/lread.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/lread.c b/src/lread.c index dc7c00bbfae..d3413d16cea 100644 --- a/src/lread.c +++ b/src/lread.c @@ -2894,19 +2894,17 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list) { EMACS_INT n = 0; Lisp_Object tem; + bool overflow = false; /* Read a non-negative integer. */ while (c >= '0' && c <= '9') { - if (MOST_POSITIVE_FIXNUM / 10 < n - || MOST_POSITIVE_FIXNUM < n * 10 + c - '0') - n = MOST_POSITIVE_FIXNUM + 1; - else - n = n * 10 + c - '0'; + overflow |= INT_MULTIPLY_WRAPV (n, 10, &n); + overflow |= INT_ADD_WRAPV (n, c - '0', &n); c = READCHAR; } - if (n <= MOST_POSITIVE_FIXNUM) + if (!overflow && n <= MOST_POSITIVE_FIXNUM) { if (c == 'r' || c == 'R') return read_integer (readcharfun, n); |