From: PatR Date: Sun, 5 Mar 2017 03:45:15 +0000 (-0800) Subject: more DUMPLOG lint X-Git-Tag: NetHack-3.6.1_RC01~517 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=10706ef0952a2a853045091f9848523099e40105;p=nethack more DUMPLOG lint 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. --- diff --git a/src/windows.c b/src/windows.c index 764662075..70c9feee7 100644 --- a/src/windows.c +++ b/src/windows.c @@ -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",