[tz] [PATCH 1/3] Further removal of attempt to support floating-point time_t.

Paul Eggert eggert at cs.ucla.edu
Fri Aug 16 19:21:55 UTC 2013


* localtime.c (timesub):
* zdump.c (my_localtime): Don't worry about time_t being floating-point.
* localtime.c (timesub): Avoid undefined behavior on integer
overflow when assigning time_t to int.
---
 localtime.c | 5 +++--
 zdump.c     | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/localtime.c b/localtime.c
index 5312ad9..f58b20a 100644
--- a/localtime.c
+++ b/localtime.c
@@ -1489,9 +1489,10 @@ timesub(const time_t *const timep, const int_fast32_t offset,
 		register int	leapdays;
 
 		tdelta = tdays / DAYSPERLYEAR;
-		idelta = tdelta;
-		if (tdelta - idelta >= 1 || idelta - tdelta >= 1)
+		if (! ((! TYPE_SIGNED(time_t) || INT_MIN <= tdelta)
+		       && tdelta <= INT_MAX))
 			return NULL;
+		idelta = tdelta;
 		if (idelta == 0)
 			idelta = (tdays < 0) ? -1 : 1;
 		newy = y;
diff --git a/zdump.c b/zdump.c
index 36c1838..fa5f8d8 100644
--- a/zdump.c
+++ b/zdump.c
@@ -244,7 +244,7 @@ my_localtime(time_t *tp)
 
 		tm = *tmp;
 		t = mktime(&tm);
-		if (t - *tp >= 1 || *tp - t >= 1) {
+		if (t != *tp) {
 			(void) fflush(stdout);
 			(void) fprintf(stderr, "\n%s: ", progname);
 			(void) fprintf(stderr, tformat(), *tp);
-- 
1.8.1.2



More information about the tz mailing list