Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/date check return value of localtime.



details:   https://anonhg.NetBSD.org/src/rev/ff55de0f06ae
branches:  trunk
changeset: 759546:ff55de0f06ae
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Dec 12 17:30:23 2010 +0000

description:
check return value of localtime.

diffstat:

 bin/date/date.c |  17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diffs (54 lines):

diff -r 19eea87d1687 -r ff55de0f06ae bin/date/date.c
--- a/bin/date/date.c   Sun Dec 12 17:15:16 2010 +0000
+++ b/bin/date/date.c   Sun Dec 12 17:30:23 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: date.c,v 1.56 2010/12/11 16:57:51 christos Exp $ */
+/* $NetBSD: date.c,v 1.57 2010/12/12 17:30:23 christos Exp $ */
 
 /*
  * Copyright (c) 1985, 1987, 1988, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)date.c     8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: date.c,v 1.56 2010/12/11 16:57:51 christos Exp $");
+__RCSID("$NetBSD: date.c,v 1.57 2010/12/12 17:30:23 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -80,6 +80,7 @@
        const char *format;
        int ch;
        long long val;
+       struct tm *tm;
 
        setprogname(argv[0]);
        (void)setlocale(LC_ALL, "");
@@ -145,10 +146,15 @@
 
        if ((buf = malloc(bufsiz = 1024)) == NULL)
                goto bad;
-       while (strftime(buf, bufsiz, format, localtime(&tval)) == 0)
+
+       if ((tm = localtime(&tval)) == NULL)
+               err(EXIT_FAILURE, "localtime %lld failed", (long long)tval);
+
+       while (strftime(buf, bufsiz, format, tm) == 0)
                if ((buf = realloc(buf, bufsiz <<= 1)) == NULL)
                        goto bad;
-       (void)printf("%s\n", buf+1);
+
+       (void)printf("%s\n", buf + 1);
        free(buf);
        return 0;
 bad:
@@ -198,7 +204,8 @@
                badformat();
        }
 
-       lt = localtime(&tval);
+       if ((lt = localtime(&tval)) == NULL)
+               err(EXIT_FAILURE, "localtime %lld failed", (long long)tval);
 
        lt->tm_isdst = -1;                      /* Divine correct DST */
 



Home | Main Index | Thread Index | Old Index