From 09072fba183831d37d30f1d70749507307b69c8b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 11 Aug 2020 16:45:01 +0800 Subject: [PATCH] TD-1057 localtime func may crash while input < 0 in windows --- src/kit/shell/src/shellEngine.c | 4 ++++ src/os/src/windows/w64Dir.c | 2 +- tests/script/windows/compute/leastsquare.sim | 2 ++ tests/tsim/src/simExe.c | 7 ++++++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 750335a037..b0f71368ac 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -368,6 +368,10 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { tt = (time_t)(val / 1000); } + if (tt < 0) { + tt = 0; + } + struct tm* ptm = localtime(&tt); size_t pos = strftime(buf, 32, "%Y-%m-%d %H:%M:%S", ptm); diff --git a/src/os/src/windows/w64Dir.c b/src/os/src/windows/w64Dir.c index 7816dac0d6..c486cd0d40 100644 --- a/src/os/src/windows/w64Dir.c +++ b/src/os/src/windows/w64Dir.c @@ -23,7 +23,7 @@ void taosRemoveDir(char *rootDir) { int taosMkDir(const char *path, mode_t mode) { uError("%s not implemented yet", __FUNCTION__); - return -1; + return 0; } void taosMvDir(char* destDir, char *srcDir) { diff --git a/tests/script/windows/compute/leastsquare.sim b/tests/script/windows/compute/leastsquare.sim index 4cd3ad1fb9..69c8fb377b 100644 --- a/tests/script/windows/compute/leastsquare.sim +++ b/tests/script/windows/compute/leastsquare.sim @@ -69,12 +69,14 @@ if $data00 != @{slop:1.000000, intercept:1.000000}@ then endi print =============== step5 +print select leastsquares(tbcol, 1, 1) as b from $tb interval(1d) sql select leastsquares(tbcol, 1, 1) as b from $tb interval(1m) print ===> $data01 if $data01 != @{slop:1.000000, intercept:1.000000}@ then return -1 endi +print select leastsquares(tbcol, 1, 1) as b from $tb interval(1d) sql select leastsquares(tbcol, 1, 1) as b from $tb interval(1d) print ===> $data01 if $data01 != @{slop:1.000000, intercept:1.000000}@ then diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 8bc9a76545..0a1829f7c7 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -783,10 +783,15 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { break; case TSDB_DATA_TYPE_TIMESTAMP: tt = *(int64_t *)row[i] / 1000; + if (tt < 0) { + tt = 0; + } + tp = localtime(&tt); strftime(timeStr, 64, "%y-%m-%d %H:%M:%S", tp); sprintf(value, "%s.%03d", timeStr, - (int)(*((int64_t *)row[i]) % 1000)); + (int)(*((int64_t *)row[i]) % 1000)); + break; default: break; -- GitLab