From d6796258a758189ef0408c2d9116b06d67569fb8 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Tue, 7 Dec 2021 18:42:34 +0800 Subject: [PATCH] fix address sanitazer memory error --- src/client/src/tscUtil.c | 1 + src/query/src/qFilter.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 25cb9ebdf4..9332f1045c 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -5570,6 +5570,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in int jsonIndex = startColId + 1; char nullTypeKey[VARSTR_HEADER_SIZE + INT_BYTES] = {0}; varDataSetLen(nullTypeKey, INT_BYTES); + nullTypeVal[0] = TSDB_DATA_TYPE_JSON; varDataSetLen(nullTypeVal + CHAR_BYTES, INT_BYTES); *(uint32_t*)(varDataVal(nullTypeKey)) = jsonNULL; tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, nullTypeKey, false); // add json null type diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 41ccab4c99..72dec5d01c 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -2961,9 +2961,17 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_JSON){ - if(colData) colData += CHAR_BYTES; + if (!colData){ // for json->'key' is null + (*p)[i] = 1; + }else if( *(char*)colData == TSDB_DATA_TYPE_JSON){ // for json is null + colData += CHAR_BYTES; + (*p)[i] = isNull(colData, info->cunits[uidx].dataType); + }else{ + (*p)[i] = 0; + } + }else{ + (*p)[i] = ((colData == NULL) || isNull(colData, info->cunits[uidx].dataType)); } - (*p)[i] = ((colData == NULL) || isNull(colData, info->cunits[uidx].dataType)); if ((*p)[i] == 0) { all = false; } @@ -2986,10 +2994,20 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows for (int32_t i = 0; i < numOfRows; ++i) { uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; + if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_JSON){ - if(colData) colData += CHAR_BYTES; + if (!colData) { // for json->'key' is not null + (*p)[i] = 0; + }else if( *(char*)colData == TSDB_DATA_TYPE_JSON){ // for json is not null + colData += CHAR_BYTES; + (*p)[i] = !isNull(colData, info->cunits[uidx].dataType); + }else{ // for json->'key' is not null + (*p)[i] = 1; + } + }else { + (*p)[i] = ((colData != NULL) && !isNull(colData, info->cunits[uidx].dataType)); } - (*p)[i] = ((colData != NULL) && !isNull(colData, info->cunits[uidx].dataType)); + if ((*p)[i] == 0) { all = false; } -- GitLab