This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 3/9] mktime: check signed shifts on long_int and time_t, too
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: GNU C Library <libc-alpha at sourceware dot org>
- Date: Wed, 23 May 2012 10:03:02 -0700
- Subject: [PATCH 3/9] mktime: check signed shifts on long_int and time_t, too
* time/mktime.c (SHR): Check that shifts work as desired
on the types long_int and time_t too, as SHR is used on
such types.
---
ChangeLog | 5 +++++
time/mktime.c | 8 +++++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1814dc4..1917df7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -124,6 +124,11 @@
mktime: merge time_r change from gnulib
* time/mktime.c [!_LIBC]: Do not include "time_r.h".
+ mktime: check signed shifts on long_int and time_t, too
+ * time/mktime.c (SHR): Check that shifts work as desired
+ on the types long_int and time_t too, as SHR is used on
+ such types.
+
mktime: do not assume 'long' is wide enough
* time/mktime.c (verify): Move decl up.
(long_int): New type.
diff --git a/time/mktime.c b/time/mktime.c
index 6d4db69..5144987 100644
--- a/time/mktime.c
+++ b/time/mktime.c
@@ -89,9 +89,11 @@ verify (long_int_is_wide_enough, INT_MAX == INT_MAX * (long_int) 2 / 2);
implementations (e.g., UNICOS 9.0 on a Cray Y-MP EL) don't shift
right in the usual way when A < 0, so SHR falls back on division if
ordinary A >> B doesn't seem to be the usual signed shift. */
-#define SHR(a, b) \
- (-1 >> 1 == -1 \
- ? (a) >> (b) \
+#define SHR(a, b) \
+ ((-1 >> 1 == -1 \
+ && (long_int) -1 >> 1 == -1 \
+ && ((time_t) -1 >> 1 == -1 || ! TYPE_SIGNED (time_t))) \
+ ? (a) >> (b) \
: (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
/* The extra casts in the following macros work around compiler bugs,
--
1.7.6.5