Module Name:    src
Committed By:   martin
Date:           Sat Jan 15 12:31:57 UTC 2011

Modified Files:
        src/lib/libc/time: Makefile localtime.c zdump.c zic.c

Log Message:
Backout previous, it breaks the build big time and causes e.g. date(1)
and top(1) to dump core.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/time/Makefile
cvs rdiff -u -r1.52 -r1.53 src/lib/libc/time/localtime.c
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/time/zdump.c
cvs rdiff -u -r1.27 -r1.28 src/lib/libc/time/zic.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/time/Makefile
diff -u src/lib/libc/time/Makefile:1.2 src/lib/libc/time/Makefile:1.3
--- src/lib/libc/time/Makefile:1.2	Fri Jan 14 23:35:07 2011
+++ src/lib/libc/time/Makefile	Sat Jan 15 12:31:56 2011
@@ -110,10 +110,6 @@
 #  -TTZ_DOMAINDIR=\"/path\" to use "/path" for gettext directory;
 #	the default is system-supplied, typically "/usr/lib/locale"
 #  $(GCC_DEBUG_FLAGS) if you are using GCC and want lots of checking
-#  $(GCC_OVERFLOW_FLAGS) if you are using GCC 3.4 or later.
-#	If you are using a compiler other than GCC, and if it defaults to
-#	undefined behavior on integer overflow, then you need to specify a flag
-#	saying that integer arithmetic is supposed to wrap around on overflow.
 #  -DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU=1
 #	if you do not want run time warnings about formats that may cause
 #	year 2000 grief
@@ -124,7 +120,6 @@
 	-Wall -Wcast-qual -Wconversion -Wmissing-prototypes \
 	-Wnested-externs -Wpointer-arith -Wshadow \
 	-Wtraditional # -Wstrict-prototypes -Wwrite-strings
-GCC_OVERFLOW_FLAGS = -fwrapv
 #
 # If you want to use System V compatibility code, add
 #	-DUSG_COMPAT
@@ -391,7 +386,7 @@
 
 public:		$(ENCHILADA)
 		make maintainer-clean
-		make "CFLAGS=$(GCC_DEBUG_FLAGS) $(GCC_OVERFLOW_FLAGS)"
+		make "CFLAGS=$(GCC_DEBUG_FLAGS)"
 		-mkdir /tmp/,tzpublic
 		-for i in $(TDATA) ; do zic -v -d /tmp/,tzpublic $$i 2>&1 | grep -v "starting year" ; done
 		for i in $(TDATA) ; do zic -d /tmp/,tzpublic $$i || exit; done

Index: src/lib/libc/time/localtime.c
diff -u src/lib/libc/time/localtime.c:1.52 src/lib/libc/time/localtime.c:1.53
--- src/lib/libc/time/localtime.c:1.52	Fri Jan 14 23:35:07 2011
+++ src/lib/libc/time/localtime.c	Sat Jan 15 12:31:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: localtime.c,v 1.52 2011/01/14 23:35:07 christos Exp $	*/
+/*	$NetBSD: localtime.c,v 1.53 2011/01/15 12:31:57 martin Exp $	*/
 
 /*
 ** This file is in the public domain, so clarified as of
@@ -10,7 +10,7 @@
 #if 0
 static char	elsieid[] = "@(#)localtime.c	8.9";
 #else
-__RCSID("$NetBSD: localtime.c,v 1.52 2011/01/14 23:35:07 christos Exp $");
+__RCSID("$NetBSD: localtime.c,v 1.53 2011/01/15 12:31:57 martin Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -1704,10 +1704,8 @@
 	int	number0;
 
 	number0 = *number;
-	if (delta < 0 ? number0 < delta - INT_MIN : INT_MAX - delta < number0)
-		  return 1;
 	*number += delta;
-	return 0;
+	return (*number < number0) != (delta < 0);
 }
 
 static int
@@ -1716,10 +1714,8 @@
 	long	number0;
 
 	number0 = *number;
-	if (delta < 0 ? number0 < delta - LONG_MIN : LONG_MAX - delta < number0)
-		  return 1;
 	*number += delta;
-	return 0;
+	return (*number < number0) != (delta < 0);
 }
 
 static int

Index: src/lib/libc/time/zdump.c
diff -u src/lib/libc/time/zdump.c:1.18 src/lib/libc/time/zdump.c:1.19
--- src/lib/libc/time/zdump.c:1.18	Fri Jan 14 23:35:07 2011
+++ src/lib/libc/time/zdump.c	Sat Jan 15 12:31:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: zdump.c,v 1.18 2011/01/14 23:35:07 christos Exp $	*/
+/*	$NetBSD: zdump.c,v 1.19 2011/01/15 12:31:57 martin Exp $	*/
 /*
 ** This file is in the public domain, so clarified as of
 ** 2009-05-17 by Arthur David Olson.
@@ -7,7 +7,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #ifndef NOID
-__RCSID("$NetBSD: zdump.c,v 1.18 2011/01/14 23:35:07 christos Exp $");
+__RCSID("$NetBSD: zdump.c,v 1.19 2011/01/15 12:31:57 martin Exp $");
 #endif /* !defined NOID */
 #endif /* !defined lint */
 
@@ -26,7 +26,6 @@
 #include "stdlib.h"	/* for exit, malloc, atoi */
 #include <err.h>
 #include "float.h"	/* for FLT_MAX and DBL_MAX */
-#include "limits.h"	/* for INT_MAX, LONG_MAX, etc. */
 #include "ctype.h"	/* for isalpha et al. */
 #ifndef isascii
 #define isascii(x) 1
@@ -432,25 +431,21 @@
 		}
 	} else if (0 > (time_t) -1) {
 		/*
-		** time_t is signed.
+		** time_t is signed.  Assume overflow wraps around.
 		*/
-		if (sizeof (time_t) == sizeof (int)) {
-			absolute_min_time = INT_MIN;
-			absolute_max_time = INT_MAX;
-		} else if (sizeof (time_t) == sizeof (long)) {
-			absolute_min_time = LONG_MIN;
-			absolute_max_time = LONG_MAX;
-#if defined LLONG_MIN && defined LLONG_MAX
-		} else if (sizeof (time_t) == sizeof (long long)) {
-			absolute_min_time = LLONG_MIN;
-			absolute_max_time = LLONG_MAX;
-#endif
-		} else {
-			(void) fprintf(stderr,
-_("%s: use of -v on system with signed time_t whose extrema are unknown\n"),
-				progname);
-			exit(EXIT_FAILURE);
+		time_t t = 0;
+		time_t t1 = 1;
+
+		while (t < t1) {
+			t = t1;
+			t1 = 2 * t1 + 1;
 		}
+
+		absolute_max_time = t;
+		t = -t;
+		absolute_min_time = t - 1;
+		if (t < absolute_min_time)
+			absolute_min_time = t;
 	} else {
 		/*
 		** time_t is unsigned.

Index: src/lib/libc/time/zic.c
diff -u src/lib/libc/time/zic.c:1.27 src/lib/libc/time/zic.c:1.28
--- src/lib/libc/time/zic.c:1.27	Fri Jan 14 23:35:07 2011
+++ src/lib/libc/time/zic.c	Sat Jan 15 12:31:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: zic.c,v 1.27 2011/01/14 23:35:07 christos Exp $	*/
+/*	$NetBSD: zic.c,v 1.28 2011/01/15 12:31:57 martin Exp $	*/
 /*
 ** This file is in the public domain, so clarified as of
 ** 2006-07-17 by Arthur David Olson.
@@ -10,7 +10,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: zic.c,v 1.27 2011/01/14 23:35:07 christos Exp $");
+__RCSID("$NetBSD: zic.c,v 1.28 2011/01/15 12:31:57 martin Exp $");
 #endif /* !defined lint */
 
 static char	elsieid[] = "@(#)zic.c	8.20";
@@ -2496,11 +2496,14 @@
 const long	t1;
 const long	t2;
 {
-	if (t2 < 0 ? t1 < t2 - LONG_MIN : LONG_MAX - t2 < t1) {
+	register long	t;
+
+	t = t1 + t2;
+	if ((t2 > 0 && t <= t1) || (t2 < 0 && t >= t1)) {
 		error(_("time overflow"));
 		exit(EXIT_FAILURE);
 	}
-	return t1 + t2;
+	return t;
 }
 
 static zic_t
@@ -2508,15 +2511,18 @@
 const zic_t	t1;
 const long	t2;
 {
+	register zic_t	t;
+
 	if (t1 == max_time && t2 > 0)
 		return max_time;
 	if (t1 == min_time && t2 < 0)
 		return min_time;
-	if (t2 < 0 ? t1 < t2 - LONG_MIN : LONG_MAX - t2 < t1) {
+	t = t1 + t2;
+	if ((t2 > 0 && t <= t1) || (t2 < 0 && t >= t1)) {
 		error(_("time overflow"));
 		exit(EXIT_FAILURE);
 	}
-	return t1 + t2;
+	return t;
 }
 
 /*

Reply via email to