diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 7e9fc7d80ef4cdb2c0660dbad15b7e04af9aab21..c04f8888c8072182f629b0ace3151adc99a6a1aa 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -409,7 +409,7 @@ static int32_t translateToJson(SFunctionNode* pFunc, char* pErrBuf, int32_t len) return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_JSON].bytes, .type = TSDB_DATA_TYPE_JSON}; + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BINARY].bytes, .type = TSDB_DATA_TYPE_BINARY}; return TSDB_CODE_SUCCESS; } diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 8681c1dd473fdf411e00b0f2b776faf376aa996f..16a4d768ba1b3a469c725851ab22af0fc0108487 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -887,13 +887,13 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu return TSDB_CODE_FAILED; } - char *input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[0]; - char *tmp = taosMemoryCalloc(pInput[0].columnData->info.bytes + 1, 1); + char tmp[TSDB_MAX_JSON_TAG_LEN] = {0}; for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { if (colDataIsNull_s(pInput[0].columnData, i)) { colDataAppendNULL(pOutput->columnData, i); continue; } + char *input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[i]; if(type == TSDB_DATA_TYPE_NCHAR){ if (varDataTLen(input) > TSDB_MAX_JSON_TAG_LEN){ @@ -912,7 +912,7 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu continue; } memcpy(tmp, varDataVal(input), varDataLen(input)); - tmp[varDataTLen(input)] = 0; + tmp[varDataLen(input)] = 0; } if(!tjsonValidateJson(tmp)){ @@ -921,9 +921,7 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu } colDataAppend(pOutput->columnData, i, input, false); - input += varDataTLen(input); } - taosMemoryFree(tmp); pOutput->numOfRows = pInput->numOfRows; diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index 59dab76989bacd88e6b56781a08399894d949b88..0b9727e0bf666b660000d4a0a57b72a6eff65fcd 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -300,8 +300,8 @@ bool tjsonValidateJson(const char *jIn) { char* jsonKey = item->string; if (!jsonKey) return false; - for (size_t j = 0; j < strlen(jsonKey); ++i) { - if (isprint(jsonKey[i]) == 0) return false; + for (size_t j = 0; j < strlen(jsonKey); ++j) { + if (isprint(jsonKey[j]) == 0) return false; } if (item->type == cJSON_Object || item->type == cJSON_Array) {