aboutsummaryrefslogtreecommitdiffstats
path: root/src/lread.c
diff options
context:
space:
mode:
authorPaul Eggert2016-09-24 02:35:13 -0700
committerPaul Eggert2016-09-24 02:35:29 -0700
commitb3e1b382456b0f7d108c57d6f902bbddfdd97b2a (patch)
treeaa3bcb76dfb30dace2811de0612a569daf250d8d /src/lread.c
parent4f05e930ca9ca4fa87aa2bc83187590432d792bd (diff)
downloademacs-b3e1b382456b0f7d108c57d6f902bbddfdd97b2a.tar.gz
emacs-b3e1b382456b0f7d108c57d6f902bbddfdd97b2a.zip
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.c10
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)
2894 { 2894 {
2895 EMACS_INT n = 0; 2895 EMACS_INT n = 0;
2896 Lisp_Object tem; 2896 Lisp_Object tem;
2897 bool overflow = false;
2897 2898
2898 /* Read a non-negative integer. */ 2899 /* Read a non-negative integer. */
2899 while (c >= '0' && c <= '9') 2900 while (c >= '0' && c <= '9')
2900 { 2901 {
2901 if (MOST_POSITIVE_FIXNUM / 10 < n 2902 overflow |= INT_MULTIPLY_WRAPV (n, 10, &n);
2902 || MOST_POSITIVE_FIXNUM < n * 10 + c - '0') 2903 overflow |= INT_ADD_WRAPV (n, c - '0', &n);
2903 n = MOST_POSITIVE_FIXNUM + 1;
2904 else
2905 n = n * 10 + c - '0';
2906 c = READCHAR; 2904 c = READCHAR;
2907 } 2905 }
2908 2906
2909 if (n <= MOST_POSITIVE_FIXNUM) 2907 if (!overflow && n <= MOST_POSITIVE_FIXNUM)
2910 { 2908 {
2911 if (c == 'r' || c == 'R') 2909 if (c == 'r' || c == 'R')
2912 return read_integer (readcharfun, n); 2910 return read_integer (readcharfun, n);