diff options
| author | Paul Eggert | 2016-09-24 02:35:13 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-09-24 02:35:29 -0700 |
| commit | b3e1b382456b0f7d108c57d6f902bbddfdd97b2a (patch) | |
| tree | aa3bcb76dfb30dace2811de0612a569daf250d8d /src/editfns.c | |
| parent | 4f05e930ca9ca4fa87aa2bc83187590432d792bd (diff) | |
| download | emacs-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/editfns.c')
| -rw-r--r-- | src/editfns.c | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/src/editfns.c b/src/editfns.c index 835e432ae3d..c5b177e41f2 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -1523,17 +1523,8 @@ static EMACS_INT | |||
| 1523 | hi_time (time_t t) | 1523 | hi_time (time_t t) |
| 1524 | { | 1524 | { |
| 1525 | time_t hi = t >> LO_TIME_BITS; | 1525 | time_t hi = t >> LO_TIME_BITS; |
| 1526 | 1526 | if (FIXNUM_OVERFLOW_P (hi)) | |
| 1527 | /* Check for overflow, helping the compiler for common cases where | ||
| 1528 | no runtime check is needed, and taking care not to convert | ||
| 1529 | negative numbers to unsigned before comparing them. */ | ||
| 1530 | if (! ((! TYPE_SIGNED (time_t) | ||
| 1531 | || MOST_NEGATIVE_FIXNUM <= TIME_T_MIN >> LO_TIME_BITS | ||
| 1532 | || MOST_NEGATIVE_FIXNUM <= hi) | ||
| 1533 | && (TIME_T_MAX >> LO_TIME_BITS <= MOST_POSITIVE_FIXNUM | ||
| 1534 | || hi <= MOST_POSITIVE_FIXNUM))) | ||
| 1535 | time_overflow (); | 1527 | time_overflow (); |
| 1536 | |||
| 1537 | return hi; | 1528 | return hi; |
| 1538 | } | 1529 | } |
| 1539 | 1530 | ||
| @@ -1595,7 +1586,7 @@ time_arith (Lisp_Object a, Lisp_Object b, | |||
| 1595 | struct lisp_time ta = lisp_time_struct (a, &alen); | 1586 | struct lisp_time ta = lisp_time_struct (a, &alen); |
| 1596 | struct lisp_time tb = lisp_time_struct (b, &blen); | 1587 | struct lisp_time tb = lisp_time_struct (b, &blen); |
| 1597 | struct lisp_time t = op (ta, tb); | 1588 | struct lisp_time t = op (ta, tb); |
| 1598 | if (! (MOST_NEGATIVE_FIXNUM <= t.hi && t.hi <= MOST_POSITIVE_FIXNUM)) | 1589 | if (FIXNUM_OVERFLOW_P (t.hi)) |
| 1599 | time_overflow (); | 1590 | time_overflow (); |
| 1600 | Lisp_Object val = Qnil; | 1591 | Lisp_Object val = Qnil; |
| 1601 | 1592 | ||
| @@ -1853,7 +1844,7 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec, | |||
| 1853 | 1844 | ||
| 1854 | if (result) | 1845 | if (result) |
| 1855 | { | 1846 | { |
| 1856 | if (! (MOST_NEGATIVE_FIXNUM <= hi && hi <= MOST_POSITIVE_FIXNUM)) | 1847 | if (FIXNUM_OVERFLOW_P (hi)) |
| 1857 | return -1; | 1848 | return -1; |
| 1858 | result->hi = hi; | 1849 | result->hi = hi; |
| 1859 | result->lo = lo; | 1850 | result->lo = lo; |