summaryrefslogtreecommitdiff
path: root/bin/date/date.c
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2014-01-21 09:09:16 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2014-01-21 09:09:16 +0000
commit5b96010fba9ede3444fb59b564df2486e32f8d4e (patch)
treef8b975b767599270067b1d0cac99baadb1097851 /bin/date/date.c
parent98eedcbba5e7e430d82e3014473015c1c40f8c8b (diff)
localtime(3) can return NULL; seen by Rod Whitworth; ok guenther@
Diffstat (limited to 'bin/date/date.c')
-rw-r--r--bin/date/date.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/bin/date/date.c b/bin/date/date.c
index 5cb0cd0f7e0..fb36c9bf3bc 100644
--- a/bin/date/date.c
+++ b/bin/date/date.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: date.c,v 1.42 2014/01/05 05:27:44 schwarze Exp $ */
+/* $OpenBSD: date.c,v 1.43 2014/01/21 09:09:15 otto Exp $ */
/* $NetBSD: date.c,v 1.11 1995/09/07 06:21:05 jtc Exp $ */
/*
@@ -60,6 +60,7 @@ int
main(int argc, char *argv[])
{
struct timezone tz;
+ struct tm *tp;
int ch, rflag;
char *format, buf[1024], *outzone = NULL;
@@ -139,7 +140,10 @@ main(int argc, char *argv[])
if (outzone)
setenv("TZ", outzone, 1);
- (void)strftime(buf, sizeof(buf), format, localtime(&tval));
+ tp = localtime(&tval);
+ if (tp == NULL)
+ errx(1, "conversion error");
+ (void)strftime(buf, sizeof(buf), format, tp);
(void)printf("%s\n", buf);
exit(0);
}