From d744ef4a33ccfd1aa0404dda938d729d5a2f7817 Mon Sep 17 00:00:00 2001 From: Xu Peng Date: Mon, 27 May 2019 10:35:41 +0800 Subject: [PATCH] fix(db): replace locatime with locatime_r for thread safe concern Former-commit-id: 1b857e297c3b26e2730f86c67e8dc798755493fe --- cpp/src/db/Meta.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cpp/src/db/Meta.cpp b/cpp/src/db/Meta.cpp index 31fdee74..3d272e06 100644 --- a/cpp/src/db/Meta.cpp +++ b/cpp/src/db/Meta.cpp @@ -4,6 +4,7 @@ * Proprietary and confidential. ******************************************************************************/ #include +#include #include "Meta.h" namespace zilliz { @@ -12,23 +13,24 @@ namespace engine { namespace meta { DateT Meta::GetDate(const std::time_t& t, int day_delta) { - tm *ltm = std::localtime(&t); + struct tm ltm; + localtime_r(&t, <m); if (day_delta > 0) { do { - ++ltm->tm_mday; + ++ltm.tm_mday; --day_delta; } while(day_delta > 0); - mktime(ltm); + mktime(<m); } else if (day_delta < 0) { do { - --ltm->tm_mday; + --ltm.tm_mday; ++day_delta; } while(day_delta < 0); - mktime(ltm); + mktime(<m); } else { - ltm->tm_mday; + ltm.tm_mday; } - return ltm->tm_year*10000 + ltm->tm_mon*100 + ltm->tm_mday; + return ltm.tm_year*10000 + ltm.tm_mon*100 + ltm.tm_mday; } DateT Meta::GetDateWithDelta(int day_delta) { -- GitLab