From de4a0047c5e43fc24b593edf229d83806b64e4b9 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 23 Feb 2023 18:00:38 +0800 Subject: [PATCH 1/3] fix coverity issue CID:399957 --- include/libs/nodes/querynodes.h | 8 ++++---- include/util/tjson.h | 1 + source/libs/nodes/src/nodesCodeFuncs.c | 2 +- source/libs/nodes/src/nodesMsgFuncs.c | 4 ++-- source/util/src/tjson.c | 9 ++++++++- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 1a9700907e..20b8bf5c46 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -38,10 +38,10 @@ typedef struct SRawExprNode { } SRawExprNode; typedef struct SDataType { - uint8_t type; - uint8_t precision; - uint8_t scale; - int32_t bytes; + uint16_t type; + uint8_t precision; + uint8_t scale; + int32_t bytes; } SDataType; typedef struct SExprNode { diff --git a/include/util/tjson.h b/include/util/tjson.h index 6922930c13..24bdc31bad 100644 --- a/include/util/tjson.h +++ b/include/util/tjson.h @@ -76,6 +76,7 @@ int32_t tjsonGetSmallIntValue(const SJson* pJson, const char* pName, int16_t* pV int32_t tjsonGetTinyIntValue(const SJson* pJson, const char* pName, int8_t* pVal); int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pVal); int32_t tjsonGetUIntValue(const SJson* pJson, const char* pName, uint32_t* pVal); +int32_t tjsonGetUSmallIntValue(const SJson* pJson, const char* pName, uint16_t* pVal); int32_t tjsonGetUTinyIntValue(const SJson* pJson, const char* pName, uint8_t* pVal); int32_t tjsonGetBoolValue(const SJson* pJson, const char* pName, bool* pVal); int32_t tjsonGetDoubleValue(const SJson* pJson, const char* pName, double* pVal); diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 099cd0d3b3..2051da1181 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -2972,7 +2972,7 @@ static int32_t dataTypeToJson(const void* pObj, SJson* pJson) { static int32_t jsonToDataType(const SJson* pJson, void* pObj) { SDataType* pNode = (SDataType*)pObj; - int32_t code = tjsonGetUTinyIntValue(pJson, jkDataTypeType, &pNode->type); + int32_t code = tjsonGetUSmallIntValue(pJson, jkDataTypeType, &pNode->type); if (TSDB_CODE_SUCCESS == code) { code = tjsonGetUTinyIntValue(pJson, jkDataTypePrecision, &pNode->precision); } diff --git a/source/libs/nodes/src/nodesMsgFuncs.c b/source/libs/nodes/src/nodesMsgFuncs.c index ad80508c64..fadce124af 100644 --- a/source/libs/nodes/src/nodesMsgFuncs.c +++ b/source/libs/nodes/src/nodesMsgFuncs.c @@ -619,7 +619,7 @@ static int32_t dataTypeToMsg(const void* pObj, STlvEncoder* pEncoder) { static int32_t msgToDataTypeInline(STlvDecoder* pDecoder, void* pObj) { SDataType* pNode = (SDataType*)pObj; - int32_t code = tlvDecodeValueI8(pDecoder, &pNode->type); + int32_t code = tlvDecodeValueU16(pDecoder, &pNode->type); if (TSDB_CODE_SUCCESS == code) { code = tlvDecodeValueU8(pDecoder, &pNode->precision); } @@ -641,7 +641,7 @@ static int32_t msgToDataType(STlvDecoder* pDecoder, void* pObj) { tlvForEach(pDecoder, pTlv, code) { switch (pTlv->type) { case DATA_TYPE_CODE_TYPE: - code = tlvDecodeI8(pTlv, &pNode->type); + code = tlvDecodeU16(pTlv, &pNode->type); break; case DATA_TYPE_CODE_PRECISION: code = tlvDecodeU8(pTlv, &pNode->precision); diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index 27d14d05b1..6741c3038f 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -250,6 +250,13 @@ int32_t tjsonGetUIntValue(const SJson* pJson, const char* pName, uint32_t* pVal) return code; } +int32_t tjsonGetUSmallIntValue(const SJson* pJson, const char* pName, uint16_t* pVal) { + uint64_t val = 0; + int32_t code = tjsonGetUBigIntValue(pJson, pName, &val); + *pVal = val; + return code; +} + int32_t tjsonGetUTinyIntValue(const SJson* pJson, const char* pName, uint8_t* pVal) { uint64_t val = 0; int32_t code = tjsonGetUBigIntValue(pJson, pName, &val); @@ -375,4 +382,4 @@ bool tjsonValidateJson(const char* jIn) { return true; } -const char* tjsonGetError() { return cJSON_GetErrorPtr(); } \ No newline at end of file +const char* tjsonGetError() { return cJSON_GetErrorPtr(); } From d34c70d172ea4e8efd58d3f52eb1769d157adaec Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 24 Feb 2023 09:57:57 +0800 Subject: [PATCH 2/3] Revert "fix coverity issue CID:399957" This reverts commit de4a0047c5e43fc24b593edf229d83806b64e4b9. --- include/libs/nodes/querynodes.h | 8 ++++---- include/util/tjson.h | 1 - source/libs/nodes/src/nodesCodeFuncs.c | 2 +- source/libs/nodes/src/nodesMsgFuncs.c | 4 ++-- source/util/src/tjson.c | 9 +-------- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 20b8bf5c46..1a9700907e 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -38,10 +38,10 @@ typedef struct SRawExprNode { } SRawExprNode; typedef struct SDataType { - uint16_t type; - uint8_t precision; - uint8_t scale; - int32_t bytes; + uint8_t type; + uint8_t precision; + uint8_t scale; + int32_t bytes; } SDataType; typedef struct SExprNode { diff --git a/include/util/tjson.h b/include/util/tjson.h index 24bdc31bad..6922930c13 100644 --- a/include/util/tjson.h +++ b/include/util/tjson.h @@ -76,7 +76,6 @@ int32_t tjsonGetSmallIntValue(const SJson* pJson, const char* pName, int16_t* pV int32_t tjsonGetTinyIntValue(const SJson* pJson, const char* pName, int8_t* pVal); int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pVal); int32_t tjsonGetUIntValue(const SJson* pJson, const char* pName, uint32_t* pVal); -int32_t tjsonGetUSmallIntValue(const SJson* pJson, const char* pName, uint16_t* pVal); int32_t tjsonGetUTinyIntValue(const SJson* pJson, const char* pName, uint8_t* pVal); int32_t tjsonGetBoolValue(const SJson* pJson, const char* pName, bool* pVal); int32_t tjsonGetDoubleValue(const SJson* pJson, const char* pName, double* pVal); diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 2051da1181..099cd0d3b3 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -2972,7 +2972,7 @@ static int32_t dataTypeToJson(const void* pObj, SJson* pJson) { static int32_t jsonToDataType(const SJson* pJson, void* pObj) { SDataType* pNode = (SDataType*)pObj; - int32_t code = tjsonGetUSmallIntValue(pJson, jkDataTypeType, &pNode->type); + int32_t code = tjsonGetUTinyIntValue(pJson, jkDataTypeType, &pNode->type); if (TSDB_CODE_SUCCESS == code) { code = tjsonGetUTinyIntValue(pJson, jkDataTypePrecision, &pNode->precision); } diff --git a/source/libs/nodes/src/nodesMsgFuncs.c b/source/libs/nodes/src/nodesMsgFuncs.c index fadce124af..ad80508c64 100644 --- a/source/libs/nodes/src/nodesMsgFuncs.c +++ b/source/libs/nodes/src/nodesMsgFuncs.c @@ -619,7 +619,7 @@ static int32_t dataTypeToMsg(const void* pObj, STlvEncoder* pEncoder) { static int32_t msgToDataTypeInline(STlvDecoder* pDecoder, void* pObj) { SDataType* pNode = (SDataType*)pObj; - int32_t code = tlvDecodeValueU16(pDecoder, &pNode->type); + int32_t code = tlvDecodeValueI8(pDecoder, &pNode->type); if (TSDB_CODE_SUCCESS == code) { code = tlvDecodeValueU8(pDecoder, &pNode->precision); } @@ -641,7 +641,7 @@ static int32_t msgToDataType(STlvDecoder* pDecoder, void* pObj) { tlvForEach(pDecoder, pTlv, code) { switch (pTlv->type) { case DATA_TYPE_CODE_TYPE: - code = tlvDecodeU16(pTlv, &pNode->type); + code = tlvDecodeI8(pTlv, &pNode->type); break; case DATA_TYPE_CODE_PRECISION: code = tlvDecodeU8(pTlv, &pNode->precision); diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index 6741c3038f..27d14d05b1 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -250,13 +250,6 @@ int32_t tjsonGetUIntValue(const SJson* pJson, const char* pName, uint32_t* pVal) return code; } -int32_t tjsonGetUSmallIntValue(const SJson* pJson, const char* pName, uint16_t* pVal) { - uint64_t val = 0; - int32_t code = tjsonGetUBigIntValue(pJson, pName, &val); - *pVal = val; - return code; -} - int32_t tjsonGetUTinyIntValue(const SJson* pJson, const char* pName, uint8_t* pVal) { uint64_t val = 0; int32_t code = tjsonGetUBigIntValue(pJson, pName, &val); @@ -382,4 +375,4 @@ bool tjsonValidateJson(const char* jIn) { return true; } -const char* tjsonGetError() { return cJSON_GetErrorPtr(); } +const char* tjsonGetError() { return cJSON_GetErrorPtr(); } \ No newline at end of file From 49fc02c52e95c8fdcc4d2271f21c6b7b21e58895 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 24 Feb 2023 10:08:53 +0800 Subject: [PATCH 3/3] fix coverity issue --- include/common/ttypes.h | 4 ---- source/common/src/tvariant.c | 33 --------------------------------- source/libs/scalar/src/filter.c | 18 +----------------- 3 files changed, 1 insertion(+), 54 deletions(-) diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 97ae151b7a..f8a85ee1b0 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -53,10 +53,6 @@ typedef struct { #define varDataNetLen(v) (htons(((VarDataLenT *)(v))[0])) #define varDataNetTLen(v) (sizeof(VarDataLenT) + varDataNetLen(v)) -// this data type is internally used only in 'in' query to hold the values -#define TSDB_DATA_TYPE_POINTER_ARRAY (1000) -#define TSDB_DATA_TYPE_VALUE_ARRAY (1001) - #define GET_TYPED_DATA(_v, _finalType, _type, _data) \ do { \ switch (_type) { \ diff --git a/source/common/src/tvariant.c b/source/common/src/tvariant.c index de225581a6..db69fe9d48 100644 --- a/source/common/src/tvariant.c +++ b/source/common/src/tvariant.c @@ -145,19 +145,6 @@ void taosVariantDestroy(SVariant *pVar) { pVar->nLen = 0; } - // NOTE: this is only for string array - if (pVar->nType == TSDB_DATA_TYPE_POINTER_ARRAY) { - size_t num = taosArrayGetSize(pVar->arr); - for (size_t i = 0; i < num; i++) { - void *p = taosArrayGetP(pVar->arr, i); - taosMemoryFree(p); - } - taosArrayDestroy(pVar->arr); - pVar->arr = NULL; - } else if (pVar->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { - taosArrayDestroy(pVar->arr); - pVar->arr = NULL; - } } void taosVariantAssign(SVariant *pDst, const SVariant *pSrc) { @@ -180,28 +167,8 @@ void taosVariantAssign(SVariant *pDst, const SVariant *pSrc) { if (IS_NUMERIC_TYPE(pSrc->nType) || (pSrc->nType == TSDB_DATA_TYPE_BOOL)) { pDst->i = pSrc->i; - } else if (pSrc->nType == TSDB_DATA_TYPE_POINTER_ARRAY) { // this is only for string array - size_t num = taosArrayGetSize(pSrc->arr); - pDst->arr = taosArrayInit(num, sizeof(char *)); - for (size_t i = 0; i < num; i++) { - char *p = (char *)taosArrayGetP(pSrc->arr, i); - char *n = strdup(p); - taosArrayPush(pDst->arr, &n); - } - } else if (pSrc->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { - size_t num = taosArrayGetSize(pSrc->arr); - pDst->arr = taosArrayInit(num, sizeof(int64_t)); - pDst->nLen = pSrc->nLen; - ASSERT(pSrc->nLen == num); - for (size_t i = 0; i < num; i++) { - int64_t *p = taosArrayGet(pSrc->arr, i); - taosArrayPush(pDst->arr, p); - } } - if (pDst->nType != TSDB_DATA_TYPE_POINTER_ARRAY && pDst->nType != TSDB_DATA_TYPE_VALUE_ARRAY) { - pDst->nLen = tDataTypes[pDst->nType].bytes; - } } int32_t taosVariantCompare(const SVariant *p1, const SVariant *p2) { diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 25e65d2588..c0c8072d81 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -1651,12 +1651,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) SValueNode *var = (SValueNode *)field->desc; SDataType *dType = &var->node.resType; - // if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { - // qDebug("VAL%d => [type:TS][val:[%" PRIi64 "] - [%" PRId64 "]]", i, *(int64_t *)field->data, - // *(((int64_t *)field->data) + 1)); - // } else { qDebug("VAL%d => [type:%d][val:%" PRIx64 "]", i, dType->type, var->datum.i); // TODO - //} } else if (field->data) { qDebug("VAL%d => [type:NIL][val:NIL]", i); // TODO } @@ -1976,18 +1971,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) { fi->data = taosMemoryCalloc(1, bytes); } else { - if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { // TIME RANGE - /* - fi->data = taosMemoryCalloc(dType->bytes, tDataTypes[type].bytes); - for (int32_t a = 0; a < dType->bytes; ++a) { - int64_t *v = taosArrayGet(var->arr, a); - assignVal((char *)fi->data + a * tDataTypes[type].bytes, (char *)v, 0, type); - } - */ - continue; - } else { - fi->data = taosMemoryCalloc(1, sizeof(int64_t)); - } + fi->data = taosMemoryCalloc(1, sizeof(int64_t)); } if (dType->type == type) {