CUtils::ParseServerTime(): fix handling of invalid timestamps

This commit is contained in:
J-P Nurmi
2015-09-18 01:16:01 +02:00
parent f1973fe81b
commit 683379df7d
2 changed files with 11 additions and 4 deletions
+7 -4
View File
@@ -463,10 +463,13 @@ timeval CUtils::ParseServerTime(const CString& sTime) {
memset(&stm, 0, sizeof(stm));
const char* cp = strptime(sTime.c_str(), "%Y-%m-%dT%H:%M:%S", &stm);
struct timeval tv;
tv.tv_sec = mktime(&stm);
CString s_usec(cp);
if (s_usec.TrimPrefix(".") && s_usec.TrimSuffix("Z")) {
tv.tv_usec = s_usec.ToULong() * 1000;
memset(&tv, 0, sizeof(stm));
if (cp) {
tv.tv_sec = mktime(&stm);
CString s_usec(cp);
if (s_usec.TrimPrefix(".") && s_usec.TrimSuffix("Z")) {
tv.tv_usec = s_usec.ToULong() * 1000;
}
}
return tv;
}