protect against bad dates

A recent fault on mingw32 revealed that faulty
code which passes a bad or out-of-range date
value could have game-fatal consequences.
Add some protection.
This commit is contained in:
nhmall
2015-04-17 00:31:22 -04:00
parent d52c6a208d
commit f6bf9f9999
+7 -1
View File
@@ -792,6 +792,7 @@ time_from_yyyymmddhhmmss(buf)
char *buf; char *buf;
{ {
int k; int k;
time_t timeresult;
struct tm t, *lt; struct tm t, *lt;
char *g, *p, y[5],mo[3],md[3],h[3],mi[3],s[3]; char *g, *p, y[5],mo[3],md[3],h[3],mi[3],s[3];
if (buf && strlen(buf) == 14) { if (buf && strlen(buf) == 14) {
@@ -829,8 +830,13 @@ char *buf;
t.tm_hour = atoi(h); t.tm_hour = atoi(h);
t.tm_min = atoi(mi); t.tm_min = atoi(mi);
t.tm_sec = atoi(s); t.tm_sec = atoi(s);
return mktime(&t); timeresult = mktime(&t);
} }
if ((int)timeresult == -1)
debugpline1("time_from_yyyymmddhhmmss(%s) would have returned -1",
buf ? buf : "");
else
return timeresult;
} }
return (time_t)0; return (time_t)0;
} }