summaryrefslogtreecommitdiff
path: root/lib/intprops.h
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/intprops.h
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/intprops.h')
-rw-r--r--lib/intprops.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/intprops.h b/lib/intprops.h
index 511a5aa989..58b1b3fbf4 100644
--- a/lib/intprops.h
+++ b/lib/intprops.h
@@ -49,11 +49,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)))
/* Return zero if T can be determined to be an unsigned type.
Otherwise, return 1.