Skip to content

Commit

Permalink
mktime: check signed shifts on long_int and time_t, too
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Paul Eggert committed May 23, 2012
1 parent f04dfbc commit 03cf7fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
2012-05-23 Paul Eggert <eggert@cs.ucla.edu>

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.
Expand Down
8 changes: 5 additions & 3 deletions time/mktime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 03cf7fe

Please sign in to comment.