]> granicus.if.org Git - file/commitdiff
check gmtime and localtime() for NULL. Apparently windows returns NULL
authorChristos Zoulas <christos@zoulas.com>
Mon, 14 Mar 2005 16:56:24 +0000 (16:56 +0000)
committerChristos Zoulas <christos@zoulas.com>
Mon, 14 Mar 2005 16:56:24 +0000 (16:56 +0000)
for time 0x80000000 (or with the high bit set).

src/file.h
src/print.c

index e9e8d809b95695c7b8bb239c85df47cf2ec58c04..6ef5c22c93a9a1373a5b14330e4f9833d3281983 100644 (file)
@@ -27,7 +27,7 @@
  */
 /*
  * file.h - definitions for file(1) program
- * @(#)$Id: file.h,v 1.66 2005/03/06 05:58:22 christos Exp $
+ * @(#)$Id: file.h,v 1.67 2005/03/14 16:56:24 christos Exp $
  */
 
 #ifndef __file_h__
@@ -245,7 +245,7 @@ struct magic_set {
 };
 
 struct stat;
-protected char *file_fmttime(uint32_t, int);
+protected const char *file_fmttime(uint32_t, int);
 protected int file_buffer(struct magic_set *, int, const void *, size_t);
 protected int file_fsmagic(struct magic_set *, const char *, struct stat *);
 protected int file_pipe2file(struct magic_set *, int, const void *, size_t);
index 81eb7895d0dd100ffe1046e1e2c71507d08d8260..a6ed790f9ccb8f67217786b025f956fd43c83614 100644 (file)
@@ -41,7 +41,7 @@
 #include <time.h>
 
 #ifndef lint
-FILE_RCSID("@(#)$Id: print.c,v 1.46 2004/11/13 08:11:39 christos Exp $")
+FILE_RCSID("@(#)$Id: print.c,v 1.47 2005/03/14 16:56:25 christos Exp $")
 #endif  /* lint */
 
 #define SZOF(a)        (sizeof(a) / sizeof(a[0]))
@@ -152,7 +152,7 @@ file_magwarn(struct magic_set *ms, const char *f, ...)
        fputc('\n', stderr);
 }
 
-protected char *
+protected const char *
 file_fmttime(uint32_t v, int local)
 {
        char *pp, *rt;
@@ -171,6 +171,8 @@ file_fmttime(uint32_t v, int local)
                        struct tm *tm1;
                        (void)time(&now);
                        tm1 = localtime(&now);
+                       if (tm1 == NULL)
+                               return "*Invalid time*";
                        daylight = tm1->tm_isdst;
                }
 #endif /* HAVE_TM_ISDST */
@@ -178,6 +180,8 @@ file_fmttime(uint32_t v, int local)
                if (daylight)
                        t += 3600;
                tm = gmtime(&t);
+               if (tm == NULL)
+                       return "*Invalid time*";
                pp = asctime(tm);
        }