From 5612ed069f5caf27ec61fa4ed7baa61f0acf8a2e Mon Sep 17 00:00:00 2001 From: xywang Date: Tue, 24 May 2022 17:29:31 +0800 Subject: [PATCH] fix(query): reverted to previous modifications and added a check --- src/client/src/tscParseLineProtocol.c | 4 ++-- src/client/src/tscUtil.c | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index d4e9363272..8ee4a2a6d9 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1298,11 +1298,11 @@ static int doSmlInsertOneDataPoint(TAOS* taos, TAOS_SML_DATA_POINT* point, SSmlL for (int col = 1; col < point->fieldNum; ++col) { TAOS_SML_KV* kv = point->fields + col; int32_t len = 0; - retLen = converToStr(sql + sqlLen, kv->type, kv->value, kv->length, &len); - if (retLen >= kv->length || retLen == TSDB_CODE_TSC_INVALID_VALUE) { + if (freeBytes - sqlLen <= kv->length) { tscError("SML:0x%" PRIx64 " no free space for converToStr", info->id); return TSDB_CODE_TSC_OUT_OF_MEMORY; } + converToStr(sql + sqlLen, kv->type, kv->value, kv->length, &len); sqlLen += len; retLen = snprintf(sql + sqlLen, freeBytes - sqlLen, ","); if (retLen >= freeBytes - sqlLen) { diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 627e1da928..ec4f2c1daf 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -42,51 +42,51 @@ int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *le switch (type) { case TSDB_DATA_TYPE_NULL: - n = snprintf(str, bufSize, "null"); + n = sprintf(str, "null"); break; case TSDB_DATA_TYPE_BOOL: - n = snprintf(str, bufSize, (*(int8_t*)buf) ? "true" : "false"); + n = sprintf(str, (*(int8_t*)buf) ? "true" : "false"); break; case TSDB_DATA_TYPE_TINYINT: - n = snprintf(str, bufSize, "%d", *(int8_t*)buf); + n = sprintf(str, "%d", *(int8_t*)buf); break; case TSDB_DATA_TYPE_SMALLINT: - n = snprintf(str, bufSize, "%d", *(int16_t*)buf); + n = sprintf(str, "%d", *(int16_t*)buf); break; case TSDB_DATA_TYPE_INT: - n = snprintf(str, bufSize, "%d", *(int32_t*)buf); + n = sprintf(str, "%d", *(int32_t*)buf); break; case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: - n = snprintf(str, bufSize, "%" PRId64, *(int64_t*)buf); + n = sprintf(str, "%" PRId64, *(int64_t*)buf); break; case TSDB_DATA_TYPE_UTINYINT: - n = snprintf(str, bufSize, "%d", *(uint8_t*)buf); + n = sprintf(str, "%d", *(uint8_t*)buf); break; case TSDB_DATA_TYPE_USMALLINT: - n = snprintf(str, bufSize, "%d", *(uint16_t*)buf); + n = sprintf(str, "%d", *(uint16_t*)buf); break; case TSDB_DATA_TYPE_UINT: - n = snprintf(str, bufSize, "%d", *(uint32_t*)buf); + n = sprintf(str, "%d", *(uint32_t*)buf); break; case TSDB_DATA_TYPE_UBIGINT: - n = snprintf(str, bufSize, "%" PRId64, *(uint64_t*)buf); + n = sprintf(str, "%" PRId64, *(uint64_t*)buf); break; case TSDB_DATA_TYPE_FLOAT: - n = snprintf(str, bufSize, "%.*e", DECIMAL_DIG, GET_FLOAT_VAL(buf)); + n = sprintf(str, "%.*e", DECIMAL_DIG, GET_FLOAT_VAL(buf)); break; case TSDB_DATA_TYPE_DOUBLE: - n = snprintf(str, bufSize, "%.*e", DECIMAL_DIG, GET_DOUBLE_VAL(buf)); + n = sprintf(str, "%.*e", DECIMAL_DIG, GET_DOUBLE_VAL(buf)); break; case TSDB_DATA_TYPE_BINARY: -- GitLab