From d212be8a372508a26a19248b03a791400409be4b Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 26 Oct 2022 17:54:19 +0800 Subject: [PATCH] fix:defects in coverity --- source/client/inc/clientLog.h | 2 +- source/client/src/clientEnv.c | 22 +++++++++++----------- source/common/src/ttime.c | 16 ++++++++-------- source/libs/scalar/src/filter.c | 6 +++--- source/libs/scalar/src/sclvector.c | 2 +- source/util/src/tstrbuild.c | 1 + utils/test/c/sml_test.c | 29 +++++++++++++++++++++++++++++ 7 files changed, 54 insertions(+), 24 deletions(-) diff --git a/source/client/inc/clientLog.h b/source/client/inc/clientLog.h index 541717c7eb..0cb36ff61d 100644 --- a/source/client/inc/clientLog.h +++ b/source/client/inc/clientLog.h @@ -30,7 +30,7 @@ extern "C" { #define tscDebug(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSC ", DEBUG_DEBUG, cDebugFlag, __VA_ARGS__); }} while(0) #define tscTrace(...) do { if (cDebugFlag & DEBUG_TRACE) { taosPrintLog("TSC ", DEBUG_TRACE, cDebugFlag, __VA_ARGS__); }} while(0) #define tscDebugL(...) do { if (cDebugFlag & DEBUG_DEBUG) { taosPrintLongString("TSC ", DEBUG_DEBUG, cDebugFlag, __VA_ARGS__); }} while(0) -#define tscPerf(...) do { taosPrintLog("TSC ", 0, cDebugFlag, __VA_ARGS__); } while(0) +//#define tscPerf(...) do { if (cDebugFlag & DEBUG_INFO) { taosPrintLog("TSC ", DEBUG_INFO, cDebugFlag, __VA_ARGS__); }} while(0) // clang-format on #ifdef __cplusplus diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index be0e6d50dc..0f6d394611 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -77,19 +77,19 @@ static void deregisterRequest(SRequestObj *pRequest) { pRequest->self, pTscObj->id, pRequest->requestId, duration / 1000.0, num, currentInst); if (QUERY_NODE_VNODE_MODIF_STMT == pRequest->stmtType) { - tscPerf("insert duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64 - "us, exec:%" PRId64 "us", - duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart, - pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd - pRequest->metric.ctgEnd, - pRequest->metric.execEnd - pRequest->metric.semanticEnd); +// tscPerf("insert duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64 +// "us, exec:%" PRId64 "us", +// duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart, +// pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd - pRequest->metric.ctgEnd, +// pRequest->metric.execEnd - pRequest->metric.semanticEnd); atomic_add_fetch_64((int64_t *)&pActivity->insertElapsedTime, duration); } else if (QUERY_NODE_SELECT_STMT == pRequest->stmtType) { - tscPerf("select duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64 - "us, planner:%" PRId64 "us, exec:%" PRId64 "us, reqId:0x%" PRIx64, - duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart, - pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd - pRequest->metric.ctgEnd, - pRequest->metric.planEnd - pRequest->metric.semanticEnd, - pRequest->metric.resultReady - pRequest->metric.planEnd, pRequest->requestId); +// tscPerf("select duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64 +// "us, planner:%" PRId64 "us, exec:%" PRId64 "us, reqId:0x%" PRIx64, +// duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart, +// pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd - pRequest->metric.ctgEnd, +// pRequest->metric.planEnd - pRequest->metric.semanticEnd, +// pRequest->metric.resultReady - pRequest->metric.planEnd, pRequest->requestId); atomic_add_fetch_64((int64_t *)&pActivity->queryElapsedTime, duration); } diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index e0cc5bd311..1b140e6c04 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -507,29 +507,29 @@ int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char double tmp = time; switch (toUnit) { case 's': { - tmp /= (NANOSECOND_PER_SEC / factors[fromPrecision]); // the result of division is an integer time /= (NANOSECOND_PER_SEC / factors[fromPrecision]); + tmp = (double)time; break; } case 'm': - tmp /= (NANOSECOND_PER_MINUTE / factors[fromPrecision]); // the result of division is an integer time /= (NANOSECOND_PER_MINUTE / factors[fromPrecision]); + tmp = (double)time; break; case 'h': - tmp /= (NANOSECOND_PER_HOUR / factors[fromPrecision]); // the result of division is an integer time /= (NANOSECOND_PER_HOUR / factors[fromPrecision]); + tmp = (double)time; break; case 'd': - tmp /= (NANOSECOND_PER_DAY / factors[fromPrecision]); // the result of division is an integer time /= (NANOSECOND_PER_DAY / factors[fromPrecision]); + tmp = (double)time; break; case 'w': - tmp /= (NANOSECOND_PER_WEEK / factors[fromPrecision]); // the result of division is an integer time /= (NANOSECOND_PER_WEEK / factors[fromPrecision]); + tmp = (double)time; break; case 'a': - tmp /= (NANOSECOND_PER_MSEC / factors[fromPrecision]); // the result of division is an integer time /= (NANOSECOND_PER_MSEC / factors[fromPrecision]); + tmp = (double)time; break; case 'u': // the result of (NANOSECOND_PER_USEC/(double)factors[fromPrecision]) maybe a double @@ -540,13 +540,13 @@ int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char break; } case TSDB_TIME_PRECISION_MICRO: { - tmp /= 1; time /= 1; + tmp = (double)time; break; } case TSDB_TIME_PRECISION_NANO: { - tmp /= 1000; time /= 1000; + tmp = (double)time; break; } } diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index e7f3fe7b49..426274a20f 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -248,9 +248,9 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { } } - if (optr == OP_TYPE_JSON_CONTAINS && type == TSDB_DATA_TYPE_JSON) { - return 28; - } +// if (optr == OP_TYPE_JSON_CONTAINS && type == TSDB_DATA_TYPE_JSON) { +// return 28; +// } switch (type) { case TSDB_DATA_TYPE_BOOL: diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 415ceeb2bd..4cf4862136 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -505,7 +505,7 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t (*pLeftData)++; } if (typeRight == TSDB_DATA_TYPE_JSON) { - if (tTagIsJson(*pLeftData)) { + if (tTagIsJson(*pRightData)) { terrno = TSDB_CODE_QRY_JSON_NOT_SUPPORT_ERROR; return false; } diff --git a/source/util/src/tstrbuild.c b/source/util/src/tstrbuild.c index c87b889e82..915f877fe8 100644 --- a/source/util/src/tstrbuild.c +++ b/source/util/src/tstrbuild.c @@ -58,6 +58,7 @@ void taosStringBuilderAppendChar(SStringBuilder* sb, char c) { void taosStringBuilderAppendStringLen(SStringBuilder* sb, const char* str, size_t len) { taosStringBuilderEnsureCapacity(sb, len); + if(!sb->buf) return; memcpy(sb->buf + sb->pos, str, len); sb->pos += len; } diff --git a/utils/test/c/sml_test.c b/utils/test/c/sml_test.c index ab520e6638..83dfa1fc57 100644 --- a/utils/test/c/sml_test.c +++ b/utils/test/c/sml_test.c @@ -1084,6 +1084,35 @@ int sml_19221_Test() { return code; } +int sml_time_Test() { + TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0); + + TAOS_RES *pRes = taos_query(taos, "create database if not exists sml_db schemaless 1"); + taos_free_result(pRes); + + const char *sql[] = { + "meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase='2022-02-02 10:22:22' 1626006833639000000", + }; + + pRes = taos_query(taos, "use sml_db"); + taos_free_result(pRes); + + char* tmp = (char*)taosMemoryCalloc(1024, 1); + memcpy(tmp, sql[0], strlen(sql[0])); + *(char*)(tmp+44) = 0; + int32_t totalRows = 0; + pRes = taos_schemaless_insert_raw(taos, tmp, strlen(sql[0]), &totalRows, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS); + + ASSERT(totalRows == 3); + printf("%s result:%s\n", __FUNCTION__, taos_errstr(pRes)); + int code = taos_errno(pRes); + taos_free_result(pRes); + taos_close(taos); + taosMemoryFree(tmp); + + return code; +} + int main(int argc, char *argv[]) { int ret = 0; ret = smlProcess_influx_Test();