Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/stat Do not crash if a date cannot be represented (l...



details:   https://anonhg.NetBSD.org/src/rev/1984bf9a60dd
branches:  trunk
changeset: 760884:1984bf9a60dd
user:      njoly <njoly%NetBSD.org@localhost>
date:      Sat Jan 15 22:54:10 2011 +0000

description:
Do not crash if a date cannot be represented (localtime returning
NULL), use the Epoch value instead.

diffstat:

 usr.bin/stat/stat.c |  8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diffs (29 lines):

diff -r 3b82528efe08 -r 1984bf9a60dd usr.bin/stat/stat.c
--- a/usr.bin/stat/stat.c       Sat Jan 15 21:56:53 2011 +0000
+++ b/usr.bin/stat/stat.c       Sat Jan 15 22:54:10 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: stat.c,v 1.32 2010/12/16 05:42:14 dholland Exp $ */
+/*     $NetBSD: stat.c,v 1.33 2011/01/15 22:54:10 njoly Exp $ */
 
 /*
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: stat.c,v 1.32 2010/12/16 05:42:14 dholland Exp $");
+__RCSID("$NetBSD: stat.c,v 1.33 2011/01/15 22:54:10 njoly Exp $");
 #endif
 
 #if ! HAVE_NBTOOL_CONFIG_H
@@ -719,6 +719,10 @@
                small = (sizeof(secs) == 4);
                data = secs;
                tm = localtime(&secs);
+               if (tm == NULL) {
+                       secs = 0;
+                       tm = localtime(&secs);
+               }
                (void)strftime(path, sizeof(path), timefmt, tm);
                sdata = path;
                formats = FMTF_DECIMAL | FMTF_OCTAL | FMTF_UNSIGNED | FMTF_HEX |



Home | Main Index | Thread Index | Old Index