- handle possible null result of localtime

This commit is contained in:
Dmytro Bogovych 2020-06-03 12:34:10 +03:00
parent 2986655930
commit 9ec2f734d8
1 changed files with 3 additions and 2 deletions

View File

@ -283,10 +283,11 @@ std::string StringHelper::trim(const std::string &s)
std::string StringHelper::timeToString(time_t t) std::string StringHelper::timeToString(time_t t)
{ {
char buffer[96]; char buffer[128] = "";
struct tm lt; struct tm lt;
#if defined(TARGET_LINUX) || defined(TARGET_OSX) || defined(TARGET_ANDROID) #if defined(TARGET_LINUX) || defined(TARGET_OSX) || defined(TARGET_ANDROID)
localtime_r(&t, &lt); if (localtime_r(&t, &lt) == nullptr)
return std::string();
#else #else
lt = *localtime(&t); lt = *localtime(&t);
#endif #endif