From 309076cd03703947345b460542ac30592627eb48 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Thu, 7 May 2020 18:26:19 +0800 Subject: [PATCH] [td-245] --- src/client/src/tscParseInsert.c | 11 ++++++----- src/util/inc/ttimer.h | 4 ++++ src/util/inc/tutil.h | 5 +---- src/util/src/tutil.c | 13 +++++++------ tests/tsim/src/simExe.c | 2 +- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 5cb13c4464..5401e500bd 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -327,15 +327,16 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload, *(uint32_t*) payload = TSDB_DATA_NCHAR_NULL; } else { // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long' - int32_t resLen = -1; - if (!taosMbsToUcs4(pToken->z, pToken->n, payload + VARSTR_HEADER_SIZE, pSchema->bytes - VARSTR_HEADER_SIZE, &resLen)) { - char buf[512] = {0}; - snprintf(buf, 512, "%s", strerror(errno)); + size_t wcharLength = 0; + if (!taosMbsToUcs4(pToken->z, pToken->n, payload + VARSTR_HEADER_SIZE, pSchema->bytes - VARSTR_HEADER_SIZE, + &wcharLength)) { + char buf[512] = {0}; + snprintf(buf, tListLen(buf), "%s", strerror(errno)); return tscInvalidSQLErrMsg(msg, buf, pToken->z); } - *(uint16_t*)payload = (uint16_t) (resLen * TSDB_NCHAR_SIZE); + *(uint16_t*) payload = (uint16_t) (wcharLength); } break; diff --git a/src/util/inc/ttimer.h b/src/util/inc/ttimer.h index 9422312856..3649a8d2f1 100644 --- a/src/util/inc/ttimer.h +++ b/src/util/inc/ttimer.h @@ -40,6 +40,10 @@ bool taosTmrReset(TAOS_TMR_CALLBACK fp, int mseconds, void *param, void *handle, void taosTmrCleanUp(void *handle); +int32_t taosInitTimer(void (*callback)(int), int32_t ms); + +void taosUninitTimer(); + #ifdef __cplusplus } #endif diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index b03e0a1c5b..09f396e799 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -141,10 +141,7 @@ int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstP */ void getTmpfilePath(const char *fileNamePattern, char *dstPath); -int32_t taosInitTimer(void (*callback)(int), int32_t ms); -void taosUninitTimer(); - -bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t* len); +bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, size_t* len); int tasoUcs4Compare(void* f1_ucs4, void *f2_ucs4, int bytes); diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 396f6f1ef8..52f70bdf5e 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -490,25 +490,26 @@ bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) { #endif } -bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t* len) { +bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, size_t* len) { memset(ucs4, 0, ucs4_max_len); #ifdef USE_LIBICONV iconv_t cd = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset); - size_t ucs4_input_len = mbs_len; - size_t outLen = ucs4_max_len; - if (iconv(cd, &mbs, &ucs4_input_len, &ucs4, &outLen) == -1) { + size_t ucs4_input_len = mbsLength; + size_t outLeft = ucs4_max_len; + if (iconv(cd, &mbs, &ucs4_input_len, &ucs4, &outLeft) == -1) { iconv_close(cd); return false; } + iconv_close(cd); if (len != NULL) { - *len = outLen; + *len = ucs4_max_len - outLeft; } return true; #else mbstate_t state = {0}; - int32_t len = mbsnrtowcs((wchar_t *) ucs4, (const char **) &mbs, mbs_len, ucs4_max_len / 4, &state); + int32_t len = mbsnrtowcs((wchar_t *) ucs4, (const char **) &mbs, mbsLength, ucs4_max_len / 4, &state); return len >= 0; #endif } diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index d0d798343a..660ed6f44f 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -688,7 +688,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { } if (row[i] == 0) { - strcpy(value, "null"); + strcpy(value, TSDB_DATA_NULL_STR); continue; }