From 041b84c13169bc9e0cac81c21f1199ad61a1fb11 Mon Sep 17 00:00:00 2001 From: kailixu Date: Wed, 10 Apr 2024 10:23:48 +0800 Subject: [PATCH] enh: tag value for nchar --- source/libs/parser/src/parInsertSql.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index afdd6089d2..731480d0e4 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -664,11 +664,13 @@ static int32_t parseTagToken(const char** end, SToken* pToken, SSchema* pSchema, case TSDB_DATA_TYPE_NCHAR: { int32_t output = 0; - void* p = taosMemoryCalloc(1, pSchema->bytes - VARSTR_HEADER_SIZE); + int64_t realLen = pToken->n << 2; + if (realLen > pSchema->bytes - VARSTR_HEADER_SIZE) realLen = pSchema->bytes - VARSTR_HEADER_SIZE; + void* p = taosMemoryMalloc(realLen); if (p == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)(p), pSchema->bytes - VARSTR_HEADER_SIZE, &output)) { + if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)(p), realLen, &output)) { if (errno == E2BIG) { taosMemoryFree(p); return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);