From c86bda4a1bbd7ec15c9a25ca92caefdea36d35d0 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Sun, 15 Aug 2021 23:01:57 +0800 Subject: [PATCH] [TD-6054]: Filtered by tag with nchar value not as expected --- src/util/src/tcompare.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index a3c01d2be7..1043ee4c37 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -152,11 +152,18 @@ int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) { int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) { int32_t len1 = varDataLen(pLeft); int32_t len2 = varDataLen(pRight); - + if (len1 != len2) { return len1 > len2? 1:-1; } else { - int32_t ret = wcsncmp(varDataVal(pLeft), varDataVal(pRight), len1/TSDB_NCHAR_SIZE); + char pLeftTerm[len1 + 1]; + char pRightTerm[len2 + 1]; + memset(pLeftTerm, 0, len1 + 1); + memset(pRightTerm, 0, len2 + 1); + memcpy(pLeftTerm, varDataVal(pLeft), len1); + memcpy(pRightTerm, varDataVal(pRight), len2); + + int32_t ret = wcsncmp((void *)pLeftTerm, (void *)pRightTerm, len1/TSDB_NCHAR_SIZE); if (ret == 0) { return 0; } else { -- GitLab