Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Oct 2010 07:14:46 +0000 (UTC)
From:      Edwin Groothuis <edwin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r214411 - in head/contrib/tzcode: stdtime zic
Message-ID:  <201010270714.o9R7EkHU093412@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: edwin
Date: Wed Oct 27 07:14:46 2010
New Revision: 214411
URL: http://svn.freebsd.org/changeset/base/214411

Log:
  Sync code with tzcode2010m
  
  asctime.c:
  * Set errno to EINVAL and return "??? ??? ?? ??:??:?? ????\n" if
    asctime_r is called with a NULL struct tm pointer.  (Note that
    asctime_r is called by ctime_r and asctime; asctime is called by
    ctime.)
  
  localtime.c:
  * Set errno to EINVAL and return WRONG if time1 is called with a
    NULL struct tm pointer; avoid dereference if a NULL struct tm
    pointer is passed to timelocal, timegm, or timeoff.  (Note that
    time1 is called by mktime, timegm, and timeoff; mktime is called
    by timelocal.)
  * more core-avoidance work
  * Change to set timezone and altzone based on time types with
    greatest transition times (for the benefit of Asia/Seoul).
  
  zic.8:
  * Warning about case-sensitivity of names, but not of abbrevations
  
  zic.c:
  * Conditionally output extra types with most-recently-use offsets
    last (for use by systems with pre-2011 versions of localtime.c,
    helping to ensure that globals "altzone and "timezone" get set
    correctly).
  
  The code has been running for nearly four weeks on my laptop running
  FreeBSD 8.1 without a problem.
  
  MFC after:	1 month

Modified:
  head/contrib/tzcode/stdtime/asctime.c
  head/contrib/tzcode/stdtime/localtime.c
  head/contrib/tzcode/zic/zic.8
  head/contrib/tzcode/zic/zic.c

Modified: head/contrib/tzcode/stdtime/asctime.c
==============================================================================
--- head/contrib/tzcode/stdtime/asctime.c	Wed Oct 27 04:19:07 2010	(r214410)
+++ head/contrib/tzcode/stdtime/asctime.c	Wed Oct 27 07:14:46 2010	(r214411)
@@ -12,7 +12,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #ifndef NOID
-static char	elsieid[] __unused = "@(#)asctime.c	8.2";
+static char	elsieid[] __unused = "@(#)asctime.c	8.5";
 #endif /* !defined NOID */
 #endif /* !defined lint */
 __FBSDID("$FreeBSD$");
@@ -95,6 +95,10 @@ char *			buf;
 	char			year[INT_STRLEN_MAXIMUM(int) + 2];
 	char			result[MAX_ASCTIME_BUF_SIZE];
 
+	if (timeptr == NULL) {
+		errno = EINVAL;
+		return strcpy(buf, "??? ??? ?? ??:??:?? ????\n");
+	}
 	if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
 		wn = "???";
 	else	wn = wday_name[timeptr->tm_wday];
@@ -117,10 +121,9 @@ char *			buf;
 		timeptr->tm_mday, timeptr->tm_hour,
 		timeptr->tm_min, timeptr->tm_sec,
 		year);
-	if (strlen(result) < STD_ASCTIME_BUF_SIZE || buf == buf_asctime) {
-		(void) strcpy(buf, result);
-		return buf;
-	} else {
+	if (strlen(result) < STD_ASCTIME_BUF_SIZE || buf == buf_asctime)
+		return strcpy(buf, result);
+	else {
 #ifdef EOVERFLOW
 		errno = EOVERFLOW;
 #else /* !defined EOVERFLOW */

Modified: head/contrib/tzcode/stdtime/localtime.c
==============================================================================
--- head/contrib/tzcode/stdtime/localtime.c	Wed Oct 27 04:19:07 2010	(r214410)
+++ head/contrib/tzcode/stdtime/localtime.c	Wed Oct 27 07:14:46 2010	(r214411)
@@ -6,7 +6,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #ifndef NOID
-static char	elsieid[] __unused = "@(#)localtime.c	8.9";
+static char	elsieid[] __unused = "@(#)localtime.c	8.14";
 #endif /* !defined NOID */
 #endif /* !defined lint */
 __FBSDID("$FreeBSD$");
@@ -315,34 +315,26 @@ settzname(void)
 		return;
 	}
 #endif /* defined ALL_STATE */
+	/*
+	** And to get the latest zone names into tzname. . .
+	*/
 	for (i = 0; i < sp->typecnt; ++i) {
-		const struct ttinfo * const	ttisp = &sp->ttis[i];
+		const struct ttinfo * const ttisp = &sp->ttis[sp->types[i]];
 
 		tzname[ttisp->tt_isdst] =
 			&sp->chars[ttisp->tt_abbrind];
 #ifdef USG_COMPAT
 		if (ttisp->tt_isdst)
 			daylight = 1;
-		if (i == 0 || !ttisp->tt_isdst)
+		if (!ttisp->tt_isdst)
 			timezone = -(ttisp->tt_gmtoff);
 #endif /* defined USG_COMPAT */
 #ifdef ALTZONE
-		if (i == 0 || ttisp->tt_isdst)
+		if (ttisp->tt_isdst)
 			altzone = -(ttisp->tt_gmtoff);
 #endif /* defined ALTZONE */
 	}
 	/*
-	** And to get the latest zone names into tzname. . .
-	*/
-	for (i = 0; i < sp->timecnt; ++i) {
-		const struct ttinfo * const	ttisp =
-							&sp->ttis[
-								sp->types[i]];
-
-		tzname[ttisp->tt_isdst] =
-			&sp->chars[ttisp->tt_abbrind];
-	}
-	/*
 	** Finally, scrub the abbreviations.
 	** First, replace bogus characters.
 	*/
@@ -395,6 +387,8 @@ register const int	doextend;
 					4 * TZ_MAX_TIMES];
 	} u;
 
+	sp->goback = sp->goahead = FALSE;
+
 	/* XXX The following is from OpenBSD, and I'm not sure it is correct */
 	if (name != NULL && issetugid() != 0)
 		if ((name[0] == ':' && name[1] == '/') || 
@@ -610,7 +604,6 @@ register const int	doextend;
 					sp->ttis[sp->typecnt++] = ts.ttis[1];
 			}
 	}
-	sp->goback = sp->goahead = FALSE;
 	if (sp->timecnt > 1) {
 		for (i = 1; i < sp->timecnt; ++i)
 			if (typesequiv(sp, sp->types[i], sp->types[0]) &&
@@ -1221,7 +1214,7 @@ tzsetwall_basic(int rdlocked)
 
 #ifdef ALL_STATE
 	if (lclptr == NULL) {
-		lclptr = (struct state *) malloc(sizeof *lclptr);
+		lclptr = (struct state *) calloc(1, sizeof *lclptr);
 		if (lclptr == NULL) {
 			settzname();	/* all we can do */
 			_RWLOCK_UNLOCK(&lcl_rwlock);
@@ -1273,7 +1266,7 @@ tzset_basic(int rdlocked)
 
 #ifdef ALL_STATE
 	if (lclptr == NULL) {
-		lclptr = (struct state *) malloc(sizeof *lclptr);
+		lclptr = (struct state *) calloc(1, sizeof *lclptr);
 		if (lclptr == NULL) {
 			settzname();	/* all we can do */
 			_RWLOCK_UNLOCK(&lcl_rwlock);
@@ -1471,7 +1464,7 @@ gmt_init(void)
 {
 
 #ifdef ALL_STATE
-	gmtptr = (struct state *) malloc(sizeof *gmtptr);
+	gmtptr = (struct state *) calloc(1, sizeof *gmtptr);
 	if (gmtptr != NULL)
 #endif /* defined ALL_STATE */
 		gmtload(gmtptr);
@@ -2054,6 +2047,11 @@ const long		offset;
 	int				types[TZ_MAX_TYPES];
 	int				okay;
 
+	if (tmp == NULL) {
+		errno = EINVAL;
+		return WRONG;
+	}
+
 	if (tmp->tm_isdst > 1)
 		tmp->tm_isdst = 1;
 	t = time2(tmp, funcp, offset, &okay);
@@ -2129,7 +2127,8 @@ time_t
 timelocal(tmp)
 struct tm * const	tmp;
 {
-	tmp->tm_isdst = -1;	/* in case it wasn't initialized */
+	if (tmp != NULL)
+		tmp->tm_isdst = -1;	/* in case it wasn't initialized */
 	return mktime(tmp);
 }
 
@@ -2137,7 +2136,8 @@ time_t
 timegm(tmp)
 struct tm * const	tmp;
 {
-	tmp->tm_isdst = 0;
+	if (tmp != NULL)
+		tmp->tm_isdst = 0;
 	return time1(tmp, gmtsub, 0L);
 }
 
@@ -2146,7 +2146,8 @@ timeoff(tmp, offset)
 struct tm * const	tmp;
 const long		offset;
 {
-	tmp->tm_isdst = 0;
+	if (tmp != NULL)
+		tmp->tm_isdst = 0;
 	return time1(tmp, gmtsub, offset);
 }
 

Modified: head/contrib/tzcode/zic/zic.8
==============================================================================
--- head/contrib/tzcode/zic/zic.8	Wed Oct 27 04:19:07 2010	(r214410)
+++ head/contrib/tzcode/zic/zic.8	Wed Oct 27 07:14:46 2010	(r214411)
@@ -119,6 +119,9 @@ Any line that is blank (after comment st
 Non-blank lines are expected to be of one of three types:
 rule lines, zone lines, and link lines.
 .Pp
+Names (such as month names) must be in English and are case insensitive.
+Abbreviations, if used, must be unambiguous in context.
+.Pp
 A rule line has the form:
 .Dl "Rule	NAME	FROM	TO	TYPE	IN	ON		AT	SAVE	LETTER/S"
 For example:
@@ -460,6 +463,6 @@ standard directory used for created file
 .Xr ctime 3 ,
 .Xr tzfile 5 ,
 .Xr zdump 8
-.\" @(#)zic.8	8.5
+.\" @(#)zic.8	8.6
 .\" This file is in the public domain, so clarified as of
 .\" 2009-05-17 by Arthur David Olson.

Modified: head/contrib/tzcode/zic/zic.c
==============================================================================
--- head/contrib/tzcode/zic/zic.c	Wed Oct 27 04:19:07 2010	(r214410)
+++ head/contrib/tzcode/zic/zic.c	Wed Oct 27 07:14:46 2010	(r214411)
@@ -3,7 +3,7 @@
 ** 2006-07-17 by Arthur David Olson.
 */
 
-static const char	elsieid[] = "@(#)zic.c	8.20";
+static const char	elsieid[] = "@(#)zic.c	8.22";
 
 #ifndef lint
 static const char rcsid[] =
@@ -1588,6 +1588,53 @@ const char * const	string;
 			if (thistimei == 0)
 				writetype[0] = TRUE;
 		}
+#ifndef LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH
+		/*
+		** For some pre-2011 systems: if the last-to-be-written
+		** standard (or daylight) type has an offset different from the
+		** most recently used offset,
+		** append an (unused) copy of the most recently used type
+		** (to help get global "altzone" and "timezone" variables
+		** set correctly).
+		*/
+		{
+			register int	mrudst, mrustd, hidst, histd, type;
+
+			hidst = histd = mrudst = mrustd = -1;
+			for (i = thistimei; i < thistimelim; ++i)
+				if (isdsts[types[i]])
+					mrudst = types[i];
+				else	mrustd = types[i];
+			for (i = 0; i < typecnt; ++i)
+				if (writetype[i]) {
+					if (isdsts[i])
+						hidst = i;
+					else	histd = i;
+				}
+			if (hidst >= 0 && mrudst >= 0 && hidst != mrudst &&
+				gmtoffs[hidst] != gmtoffs[mrudst]) {
+					isdsts[mrudst] = -1;
+					type = addtype(gmtoffs[mrudst],
+						&chars[abbrinds[mrudst]],
+						TRUE,
+						ttisstds[mrudst],
+						ttisgmts[mrudst]);
+					isdsts[mrudst] = TRUE;
+					writetype[type] = TRUE;
+			}
+			if (histd >= 0 && mrustd >= 0 && histd != mrustd &&
+				gmtoffs[histd] != gmtoffs[mrustd]) {
+					isdsts[mrustd] = -1;
+					type = addtype(gmtoffs[mrustd],
+						&chars[abbrinds[mrustd]],
+						FALSE,
+						ttisstds[mrustd],
+						ttisgmts[mrustd]);
+					isdsts[mrustd] = FALSE;
+					writetype[type] = TRUE;
+			}
+		}
+#endif /* !defined LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH */
 		thistypecnt = 0;
 		for (i = 0; i < typecnt; ++i)
 			typemap[i] = writetype[i] ?  thistypecnt++ : -1;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201010270714.o9R7EkHU093412>