diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index d8d43508b5ba92912bae16e1826d328269469199..87af5fb5f7363eb741ccc9d9ed2f0dffe5492c5e 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2642,7 +2642,7 @@ static int32_t doExtractColumnFilterInfo(SQueryInfo* pQueryInfo, SColumnFilterIn tVariantDump(&pRight->val, (char*)pColumnFilter->pz, colType, false); - size_t len = wcslen((wchar_t*)pColumnFilter->pz); + size_t len = twcslen((wchar_t*)pColumnFilter->pz); pColumnFilter->len = len * TSDB_NCHAR_SIZE; } else { tVariantDump(&pRight->val, (char*)&pColumnFilter->lowerBndd, colType, false); diff --git a/src/query/src/tvariant.c b/src/query/src/tvariant.c index 1650db6cfdf5c11a95953fcaeaed584e340f085b..1b64a7aefa786c69f0386186e7f2231580dd14b1 100644 --- a/src/query/src/tvariant.c +++ b/src/query/src/tvariant.c @@ -184,7 +184,7 @@ int32_t tVariantToString(tVariant *pVar, char *dst) { case TSDB_DATA_TYPE_NCHAR: { dst[0] = '\''; - taosUcs4ToMbs(pVar->wpz, (wcslen(pVar->wpz) + 1) * TSDB_NCHAR_SIZE, dst + 1); + taosUcs4ToMbs(pVar->wpz, (twcslen(pVar->wpz) + 1) * TSDB_NCHAR_SIZE, dst + 1); int32_t len = strlen(dst); dst[len] = '\''; dst[len + 1] = 0; @@ -416,7 +416,7 @@ static int32_t toNchar(tVariant *pVariant, char **pDest, int32_t *pDestSize) { } pVariant->wpz = pWStr; - *pDestSize = wcslen(pVariant->wpz); + *pDestSize = twcslen(pVariant->wpz); // shrink the allocate memory, no need to check here. char* tmp = realloc(pVariant->wpz, (*pDestSize + 1)*TSDB_NCHAR_SIZE); diff --git a/src/query/tests/unitTest.cpp b/src/query/tests/unitTest.cpp index c5b1cbf858a69f2d905f6aa655da18eefec3a2b6..59fd326ef47aea53fcd5ba7981f6255f4bd28d88 100644 --- a/src/query/tests/unitTest.cpp +++ b/src/query/tests/unitTest.cpp @@ -66,7 +66,7 @@ static void _init_tvariant_nchar(tVariant* t) { t->wpz = (wchar_t*)calloc(1, 20 * TSDB_NCHAR_SIZE); t->nType = TSDB_DATA_TYPE_NCHAR; wcscpy(t->wpz, L"-2000000.8765"); - t->nLen = wcslen(t->wpz); + t->nLen = twcslen(t->wpz); } int main(int argc, char** argv) { diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index e3e52d46fff3cc25acea389a01e695159197011d..a314f0e31ddde3e1e58c9c8ba7bcfd89efe4b1d2 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -119,6 +119,8 @@ extern "C" { uint32_t taosRand(void); +size_t twcslen(const wchar_t *wcs); + int32_t strdequote(char *src); size_t strtrim(char *src); diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 150767643f584ae09b47cb12042cc73e627e9a9e..f8fca7392cd5a6dc9496ef67b6ae046910518b1a 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -57,6 +57,23 @@ uint32_t taosRand(void) } #endif +size_t twcslen(const wchar_t *wcs) { + int *wstr = (int *)wcs; + if (NULL == wstr) { + return 0; + } + + size_t n = 0; + while (1) { + if (0 == *wstr++) { + break; + } + n++; + } + + return n; +} + int32_t strdequote(char *z) { if (z == NULL) { return 0;