zdump -v crashes with 64-bit time_t
Ken Pizzini
tz. at explicate.org
Tue Jun 15 03:11:26 UTC 2004
On Mon, Jun 14, 2004 at 11:51:48AM -0400, Olson, Arthur David (NIH/NCI) wrote:
> Here's a proposed change to zdump to avoid crashes when NULL is returned by
> asctime.
[...]
> if (v)
> ! (void) printf("%.24s UTC = ", asctime(gmtime(&t)));
> tmp = localtime(&t);
> ! (void) printf("%.24s", asctime(tmp));
...
> if (v)
> ! (void) printf("%.24s UTC = ", nonnull(asctime(gmtime(&t))));
> tmp = localtime(&t);
> ! (void) printf("%.24s", nonnull(asctime(tmp)));
That might work, depending on the local implementation of asctime(),
but I'd feel more comfortable with a patch that takes care to avoid
passing a NULL to asctime() in the first place. Perhaps this patch
instead?
--Ken Pizzini
--- zdump.c-orig 2004-03-02 06:52:38.000000000 -0800
+++ zdump.c 2004-06-14 20:05:19.453250080 -0700
@@ -1,4 +1,4 @@
-static char elsieid[] = "@(#)zdump.c 7.31";
+static char elsieid[] = "@(#)zdump.c 7.32";
/*
** This code has been made independent of the rest of the time
@@ -334,6 +334,14 @@
return result;
}
+static char *
+null_safe_asctime(t)
+const struct tm * t;
+{
+ static char null[] = "NULL";
+ return (t == NULL) ? null : asctime(t);
+}
+
static void
show(zone, t, v)
char * zone;
@@ -344,9 +352,9 @@
(void) printf("%-*s ", (int) longest, zone);
if (v)
- (void) printf("%.24s UTC = ", asctime(gmtime(&t)));
+ (void) printf("%.24s UTC = ", null_safe_asctime(gmtime(&t)));
tmp = localtime(&t);
- (void) printf("%.24s", asctime(tmp));
+ (void) printf("%.24s", null_safe_asctime(tmp));
if (*abbr(tmp) != '\0')
(void) printf(" %s", abbr(tmp));
if (v) {
More information about the tz
mailing list