From 7eeea8a29c3d03b1dd3eac93732c38b9df4c5595 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 29 Dec 2022 17:56:20 +0800 Subject: [PATCH] fix(query): fix the invalid access, and do some internal refactor. --- source/common/src/ttypes.c | 5 ++++- source/libs/scalar/src/filter.c | 2 +- source/libs/scalar/src/sclvector.c | 14 ++------------ source/libs/scalar/test/scalar/scalarTests.cpp | 10 +++++++--- source/util/src/tcompare.c | 5 +++-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/source/common/src/ttypes.c b/source/common/src/ttypes.c index 7b5d0a8805..d412fd89da 100644 --- a/source/common/src/ttypes.c +++ b/source/common/src/ttypes.c @@ -131,7 +131,10 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) { varDataCopy(val, src); break; default: { - memcpy(val, src, len); + if (len > 0) { + memcpy(val, src, len); + } + break; } } diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 8b7651765b..d0c27560ca 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -338,7 +338,7 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { __compar_fn_t filterGetCompFunc(int32_t type, int32_t optr) { return gDataCompare[filterGetCompFuncIdx(type, optr)]; } __compar_fn_t filterGetCompFuncEx(int32_t lType, int32_t rType, int32_t optr) { - if (TSDB_DATA_TYPE_NULL == rType) { + if (TSDB_DATA_TYPE_NULL == rType || TSDB_DATA_TYPE_JSON == rType) { return NULL; } diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 24ac5be845..8f2fe87a53 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -1723,18 +1723,8 @@ void vectorCompareImpl(SScalarParam *pLeft, SScalarParam *pRight, SScalarParam * param2 = pRight; } else { vectorConvertCols(pLeft, pRight, &pLeftOut, &pRightOut, startIndex, numOfRows); - - if (pLeftOut.columnData != NULL) { - param1 = &pLeftOut; - } else { - param1 = pLeft; - } - - if (pRightOut.columnData != NULL) { - param2 = &pRightOut; - } else { - param2 = pRight; - } + param1 = (pLeftOut.columnData != NULL) ? &pLeftOut : pLeft; + param2 = (pRightOut.columnData != NULL) ? &pRightOut : pRight; } doVectorCompare(param1, param2, pOut, startIndex, numOfRows, _ord, optr); diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index f5a40c9a87..97002ed9bf 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -344,7 +344,7 @@ TEST(constantTest, int_or_binary) { ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); SValueNode *v = (SValueNode *)res; ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT); - ASSERT_EQ(v->datum.b, scltLeftV | scltRightV); + ASSERT_EQ(v->datum.i, scltLeftV | scltRightV); nodesDestroyNode(res); } @@ -1101,7 +1101,8 @@ void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, do opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH || opType == OP_TYPE_NMATCH) { printf("op:%s,3result:%d,except:%f\n", operatorTypeStr(opType), *((bool *)colDataGetData(column, 0)), exceptValue); - ASSERT_EQ(*((bool *)colDataGetData(column, 0)), exceptValue); + assert(*(bool *)colDataGetData(column, 0) == exceptValue); +// ASSERT_EQ((int) *((bool *)colDataGetData(column, 0)), (int)exceptValue); } taosArrayDestroyEx(blockList, scltFreeDataBlock); @@ -1426,7 +1427,7 @@ TEST(columnTest, json_column_logic_op) { printf("--------------------json string-- 6.6hello {1, 8, 2, 2, 3, 0, 0, 0, 0}-------------------\n"); key = "k9"; - bool eRes8[len + len1] = {false, false, false, false, false, false, false, true, true, false, true, false, true}; + bool eRes8[len + len1] = {false, false, false, false, false, false, false, true, true, false, true, true, true}; for (int i = 0; i < len; i++) { makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes8[i], op[i], false); } @@ -1437,6 +1438,9 @@ TEST(columnTest, json_column_logic_op) { for (int i = len; i < len + len1; i++) { void *rightData = prepareNchar(inputNchar[i - len]); + if (i == 11) { + printf("abc\n"); + } makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes8[i], op[i], false); taosMemoryFree(rightData); } diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index 62ccd2c50f..ca8b64fe1e 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -1161,7 +1161,8 @@ static int32_t doExecRegexMatch(const char *pString, const char *pPattern) { return 1; } - ret = regexec(®ex, pString, 0, NULL, 0); + regmatch_t pmatch[1]; + ret = regexec(®ex, pString, 1, pmatch, 0); if (ret != 0 && ret != REG_NOMATCH) { regerror(ret, ®ex, msgbuf, sizeof(msgbuf)); uDebug("Failed to match %s with pattern %s, reason %s", pString, pPattern, msgbuf) @@ -1192,7 +1193,7 @@ int32_t comparestrRegexMatch(const void *pLeft, const void *pRight) { int32_t comparewcsRegexMatch(const void* pString, const void* pPattern) { size_t len = varDataLen(pPattern); - char *pattern = taosMemoryMalloc(len + TSDB_NCHAR_SIZE); + char *pattern = taosMemoryMalloc(len + 1); int convertLen = taosUcs4ToMbs((TdUcs4 *)varDataVal(pPattern), len, pattern); if (convertLen < 0) { -- GitLab