summaryrefslogtreecommitdiff
path: root/lib/strtol.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-01-29 23:59:31 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2011-01-30 00:00:00 -0800
commitee9e39c014e2880179c91960ce1f69309d0c1500 (patch)
tree11654c2892678ea15c6fa939af91e1062bb1eb31 /lib/strtol.c
parent56887e878833f53c8ca55371c0e4be66388e157b (diff)
downloadgnulib-ee9e39c014e2880179c91960ce1f69309d0c1500.tar.gz
TYPE_MAXIMUM: avoid theoretically undefined behavior
* lib/intprops.h (TYPE_MINIMUM, TYPE_MAXIMUM): Do not shift a negative number, which the C Standard says has undefined behavior. In practice this is not a problem, but might as well do it by the book. Reported by Rich Felker and Eric Blake; see <http://lists.gnu.org/archive/html/bug-gnulib/2011-01/msg00493.html>. * lib/strtol.c (TYPE_MINIMUM, TYPE_MAXIMUM): Likewise. * m4/mktime.m4 (AC_FUNC_MKTIME): Likewise. * m4/nanosleep.m4 (gl_FUNC_NANOSLEEP): Likewise. * m4/parse-datetime.m4 (gl_PARSE_DATETIME): Likewise. * m4/stdint.m4 (gl_STDINT_H): Likewise. * lib/mktime.c (TYPE_MAXIMUM): Redo slightly to match the others.
Diffstat (limited to 'lib/strtol.c')
-rw-r--r--lib/strtol.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/strtol.c b/lib/strtol.c
index 747d70ed3f..b6a761ecb9 100644
--- a/lib/strtol.c
+++ b/lib/strtol.c
@@ -141,11 +141,11 @@
? (t) 0 \
: TYPE_SIGNED_MAGNITUDE (t) \
? ~ (t) 0 \
- : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))
+ : ~ TYPE_MAXIMUM (t)))
# define TYPE_MAXIMUM(t) \
((t) (! TYPE_SIGNED (t) \
? (t) -1 \
- : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
+ : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
# ifndef ULLONG_MAX
# define ULLONG_MAX TYPE_MAXIMUM (unsigned long long)