]> granicus.if.org Git - nethack/commitdiff
more DUMPLOG lint
authorPatR <rankin@nethack.org>
Sun, 5 Mar 2017 03:45:15 +0000 (19:45 -0800)
committerPatR <rankin@nethack.org>
Sun, 5 Mar 2017 03:45:15 +0000 (19:45 -0800)
The recently added dumplog code assumed that 'time_t' is 'long int'
or at least will give sensible results when formatted with '%ld'.
This is more of a Band-Aid(tm) than a proper fix.

src/windows.c

index 7646620755dcb0fea5fccbb2bedd9961b43f360b..70c9feee7637973670b1227877e04cebc619b584 100644 (file)
@@ -1056,6 +1056,16 @@ char *buf;
     now = dumplog_now;
     uid = (long) getuid();
 
+    /*
+     * Note: %t and %T assume that time_t is a 'long int' number of
+     * seconds since some epoch value.  That's quite iffy....  The
+     * unit of time might be different and the datum size might be
+     * some variant of 'long long int'.  [Their main purpose is to
+     * construct a unique file name rather than record the date and
+     * time; violating the 'long seconds since base-date' assumption
+     * may or may not interfere with that usage.]
+     */
+
     while (fp && *fp && len < BUFSZ-1) {
         if (*fp == '%') {
             fp++;
@@ -1064,13 +1074,13 @@ char *buf;
                 goto finish;
             case '\0': /* fallthrough */
             case '%':  /* literal % */
-                Sprintf(tmpbuf,"%%");
+                Sprintf(tmpbuf, "%%");
                 break;
             case 't': /* game start, timestamp */
-                Sprintf(tmpbuf, "%ld", ubirthday);
+                Sprintf(tmpbuf, "%lu", (unsigned long) ubirthday);
                 break;
             case 'T': /* current time, timestamp */
-                Sprintf(tmpbuf, "%ld", now);
+                Sprintf(tmpbuf, "%lu", (unsigned long) now);
                 break;
             case 'd': /* game start, YYYYMMDDhhmmss */
                 Sprintf(tmpbuf, "%08ld%06ld",