From f790a124b1edfa93a5463cdba1a6dddaf382a7fb Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 12 Aug 2020 05:14:59 +0000 Subject: [PATCH] localtime func crash in windows --- src/kit/shell/src/shellEngine.c | 4 ++++ tests/tsim/src/simExe.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 2838dc5386..d765eb3ad7 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -379,6 +379,10 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { } */ +#ifdef WINDOWS + if (tt < 0) tt = 0; +#endif + struct tm* ptm = localtime(&tt); size_t pos = strftime(buf, 32, "%Y-%m-%d %H:%M:%S", ptm); diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 677cea54c2..50d1a9b5be 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -791,6 +791,10 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { } */ +#ifdef WINDOWS + if (tt < 0) tt = 0; +#endif + tp = localtime(&tt); strftime(timeStr, 64, "%y-%m-%d %H:%M:%S", tp); sprintf(value, "%s.%03d", timeStr, -- GitLab