diff --git a/source/os/src/osTime.c b/source/os/src/osTime.c index 685693a709..5d5bff8c48 100644 --- a/source/os/src/osTime.c +++ b/source/os/src/osTime.c @@ -413,12 +413,16 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result) { } #ifdef WINDOWS if (*timep < 0) { + return NULL; + // TODO: bugs in following code SYSTEMTIME ss, s; FILETIME ff, f; LARGE_INTEGER offset; struct tm tm1; time_t tt = 0; - localtime_s(&tm1, &tt); + if (localtime_s(&tm1, &tt) != 0 ) { + return NULL; + } ss.wYear = tm1.tm_year + 1900; ss.wMonth = tm1.tm_mon + 1; ss.wDay = tm1.tm_mday; @@ -444,7 +448,9 @@ struct tm *taosLocalTime(const time_t *timep, struct tm *result) { result->tm_yday = 0; result->tm_isdst = 0; } else { - localtime_s(result, timep); + if (localtime_s(result, timep) != 0) { + return NULL; + } } #else localtime_r(timep, result); @@ -469,12 +475,16 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst) } #ifdef WINDOWS if (*timep < 0) { + return NULL; + // TODO: bugs in following code SYSTEMTIME ss, s; FILETIME ff, f; LARGE_INTEGER offset; struct tm tm1; time_t tt = 0; - localtime_s(&tm1, &tt); + if (localtime_s(&tm1, &tt) != 0) { + return NULL; + } ss.wYear = tm1.tm_year + 1900; ss.wMonth = tm1.tm_mon + 1; ss.wDay = tm1.tm_mday; @@ -500,7 +510,9 @@ struct tm *taosLocalTimeNolock(struct tm *result, const time_t *timep, int dst) result->tm_yday = 0; result->tm_isdst = 0; } else { - localtime_s(result, timep); + if (localtime_s(result, timep) != 0) { + return NULL; + } } #elif defined(LINUX) time_t secsMin = 60, secsHour = 3600, secsDay = 3600 * 24; diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 3080b15b8c..a87ba16267 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -291,7 +291,10 @@ char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision) { } struct tm ptm = {0}; - taosLocalTime(&tt, &ptm); + if (taosLocalTime(&tt, &ptm) == NULL) { + sprintf(buf, "NaN"); + return buf; + } size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", &ptm); if (precision == TSDB_TIME_PRECISION_NANO) {