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:
+7
-1
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user