From f1dc1d63f7bcc2c48c61c2fe7e28f4150f5aa1e8 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 01/22] fix: coverity issues CID: 399714 --- source/common/src/tmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 1f0023278f..94483b8a64 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -5124,7 +5124,7 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) { char name[TSDB_COL_NAME_LEN] = {0}; char *tmp = NULL; if (tDecodeCStr(pCoder, &tmp) < 0) return -1; - strcpy(name, tmp); + strncpy(name, tmp, TSDB_COL_NAME_LEN - 1); taosArrayPush(pReq->ctb.tagName, name); } } else if (pReq->type == TSDB_NORMAL_TABLE) { From 623581a51dd6ae619f71521c5ebbe8afc895c9a5 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 02/22] fix: coverity issues CID: 399721 --- source/libs/scalar/src/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index a04d5a3a3a..9e49ae1e03 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -3712,7 +3712,7 @@ EDealRes fltReviseRewriter(SNode **pNode, void *pContext) { SListCell *cell = node->pParameterList->pHead; for (int32_t i = 0; i < node->pParameterList->length; ++i) { if (NULL == cell || NULL == cell->pNode) { - fltError("invalid cell, cell:%p, pNode:%p", cell, cell->pNode); + fltError("invalid cell"); stat->code = TSDB_CODE_QRY_INVALID_INPUT; return DEAL_RES_ERROR; } From f4c290d545b3ddc376af3a3a3e6bf0889a9ab3ab Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 03/22] fix: coverity issues CID: 399791 --- source/common/src/ttszip.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/common/src/ttszip.c b/source/common/src/ttszip.c index aeb9292b41..fe5c599d53 100644 --- a/source/common/src/ttszip.c +++ b/source/common/src/ttszip.c @@ -187,7 +187,9 @@ void* tsBufDestroy(STSBuf* pTSBuf) { if (pTSBuf->autoDelete) { // ("tsBuf %p destroyed, delete tmp file:%s", pTSBuf, pTSBuf->path); - taosRemoveFile(pTSBuf->path); + if (taosRemoveFile(pTSBuf->path) != 0) { + // tscError("tsBuf %p destroyed, failed to remove tmp file:%s", pTSBuf, pTSBuf->path); + } } else { // tscDebug("tsBuf %p destroyed, tmp file:%s, remains", pTSBuf, pTSBuf->path); } From c12f1b6e6a53a147c505b461eac1ca84b339b742 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 04/22] fix: coverity issues CID: 399890 --- source/libs/scalar/src/filter.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 9e49ae1e03..6f96f6f715 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -1135,7 +1135,12 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi int32_t filterAddUnitToGroup(SFilterGroup *group, uint32_t unitIdx) { if (group->unitNum >= group->unitSize) { group->unitSize += FILTER_DEFAULT_UNIT_SIZE; - group->unitIdxs = taosMemoryRealloc(group->unitIdxs, group->unitSize * sizeof(*group->unitIdxs)); + + void *tmp = taosMemoryRealloc(group->unitIdxs, group->unitSize * sizeof(*group->unitIdxs)); + if (tmp == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + group->unitIdxs = tmp; } group->unitIdxs[group->unitNum++] = unitIdx; From 5728685772344da7104fcedc8c160d5025e8c024 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 05/22] fix: coverity issues CID: 399907 --- source/libs/scalar/src/filter.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 6f96f6f715..3ef32a303e 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -1082,7 +1082,12 @@ int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, if (info->unitNum >= info->unitSize) { uint32_t psize = info->unitSize; info->unitSize += FILTER_DEFAULT_UNIT_SIZE; - info->units = taosMemoryRealloc(info->units, info->unitSize * sizeof(SFilterUnit)); + + void *tmp = taosMemoryRealloc(info->units, info->unitSize * sizeof(SFilterUnit)); + if (tmp == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + info->units = tmp; memset(info->units + psize, 0, sizeof(*info->units) * FILTER_DEFAULT_UNIT_SIZE); } From aa4daf1770366d00dc35f36a6a6eedb1433458cd Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 06/22] fix: coverity issues CID: 399914 --- source/common/src/tmsg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 94483b8a64..44a3f27983 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -5954,6 +5954,7 @@ int32_t tDecodeSMqDataRsp(SDecoder *pDecoder, SMqDataRsp *pRsp) { if (pSW == NULL) return -1; if (tDecodeSSchemaWrapper(pDecoder, pSW) < 0) return -1; taosArrayPush(pRsp->blockSchema, &pSW); + taosMemoryFree(pSW); } if (pRsp->withTbName) { From c2bff98311a1977a58d350506a0e91c815cc7912 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 07/22] fix: coverity issues CID: 399945 --- source/common/src/trow.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/common/src/trow.c b/source/common/src/trow.c index e1085ce5d8..08a601909e 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -948,8 +948,10 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp #ifdef TD_SUPPORT_BITMAP if (valType == TD_VTYPE_NORM) { terrno = TSDB_CODE_INVALID_PTR; - return terrno; + } else { + terrno = TSDB_CODE_INVALID_PARA; } + return terrno; #else TASSERT(0); terrno = TSDB_CODE_INVALID_PARA; @@ -1361,4 +1363,4 @@ void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColV *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, value); } -} \ No newline at end of file +} From 120a3ca4b922f6fde65d1558ba6d001cdbaf7bd9 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 08/22] fix: coverity issues CID: 400059 --- source/libs/scalar/src/sclvector.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index f089bad04e..e2c26c32e0 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -344,8 +344,11 @@ static FORCE_INLINE void varToNchar(char *buf, SScalarParam *pOut, int32_t rowIn int32_t outputMaxLen = (inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; char *t = taosMemoryCalloc(1, outputMaxLen); - /*int32_t resLen = */ taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4 *)varDataVal(t), - outputMaxLen - VARSTR_HEADER_SIZE, &len); + int32_t ret = taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4 *)varDataVal(t), + outputMaxLen - VARSTR_HEADER_SIZE, &len); + if (!ret) { + sclError("failed to convert to NCHAR"); + } varDataSetLen(t, len); colDataAppend(pOut->columnData, rowIndex, t, false); From 4780e88ce92799245a9840ca0943601a7ff4be7c Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 09/22] fix: coverity issues CID: 400330 --- source/libs/scalar/src/filter.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 3ef32a303e..e7f3fe7b49 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -4076,6 +4076,10 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, SColumnInfoData **p, SC *p = output.columnData; output.numOfRows = pSrc->info.rows; + if (*p == NULL) { + return false; + } + bool keep = (*info->func)(info, pSrc->info.rows, *p, statis, numOfCols, &output.numOfQualified); // todo this should be return during filter procedure From 68e274eba21318a3c654deabad64e5f3b26a51d5 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 10/22] fix: coverity issues CID: 399665 --- source/libs/scalar/src/scalar.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index cc1949f17d..26adad27bc 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -331,7 +331,10 @@ int32_t sclInitParam(SNode *node, SScalarParam *param, SScalarCtx *ctx, int32_t ASSERT(param->columnData == NULL); param->numOfRows = 1; - /*int32_t code = */ sclCreateColumnInfoData(&valueNode->node.resType, 1, param); + int32_t code = sclCreateColumnInfoData(&valueNode->node.resType, 1, param); + if (code != TSDB_CODE_SUCCESS) { + SCL_RET(TSDB_CODE_OUT_OF_MEMORY); + } if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type || valueNode->isNull) { colDataAppendNULL(param->columnData, 0); } else { From 1935d349d4dfe3ba16a6a29c2a80cd0b873aff72 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 11/22] fix: coverity issues CID: 399493 --- source/libs/function/src/builtins.c | 49 +++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 49facfdd14..cffe1700ed 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -209,7 +209,7 @@ static int32_t countTrailingSpaces(const SValueNode* pVal, bool isLtrim) { return numOfSpaces; } -void static addTimezoneParam(SNodeList* pList) { +static int32_t addTimezoneParam(SNodeList* pList) { char buf[6] = {0}; time_t t = taosTime(NULL); struct tm tmInfo; @@ -218,6 +218,10 @@ void static addTimezoneParam(SNodeList* pList) { int32_t len = (int32_t)strlen(buf); SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); + if (pVal == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pVal->literal = strndup(buf, len); pVal->isDuration = false; pVal->translate = true; @@ -229,10 +233,15 @@ void static addTimezoneParam(SNodeList* pList) { strncpy(varDataVal(pVal->datum.p), pVal->literal, len); nodesListAppend(pList, (SNode*)pVal); + return TSDB_CODE_SUCCESS; } -void static addDbPrecisonParam(SNodeList** pList, uint8_t precision) { +static int32_t addDbPrecisonParam(SNodeList** pList, uint8_t precision) { SValueNode* pVal = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); + if (pVal == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pVal->literal = NULL; pVal->isDuration = false; pVal->translate = true; @@ -244,6 +253,7 @@ void static addDbPrecisonParam(SNodeList** pList, uint8_t precision) { pVal->typeData = (int64_t)precision; nodesListMakeAppend(pList, (SNode*)pVal); + return TSDB_CODE_SUCCESS; } // There is only one parameter of numeric type, and the return type is parameter type @@ -465,7 +475,10 @@ static int32_t translateNowToday(SFunctionNode* pFunc, char* pErrBuf, int32_t le // add database precision as param uint8_t dbPrec = pFunc->node.resType.precision; - addDbPrecisonParam(&pFunc->pParameterList, dbPrec); + int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec); + if (code != TSDB_CODE_SUCCESS) { + return code; + } pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_TIMESTAMP}; return TSDB_CODE_SUCCESS; @@ -1487,7 +1500,10 @@ static int32_t translateIrate(SFunctionNode* pFunc, char* pErrBuf, int32_t len) // add database precision as param uint8_t dbPrec = pFunc->node.resType.precision; - addDbPrecisonParam(&pFunc->pParameterList, dbPrec); + int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec); + if (code != TSDB_CODE_SUCCESS) { + return code; + } pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; return TSDB_CODE_SUCCESS; @@ -1810,7 +1826,10 @@ static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { // add database precision as param uint8_t dbPrec = pFunc->node.resType.precision; - addDbPrecisonParam(&pFunc->pParameterList, dbPrec); + int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec); + if (code != TSDB_CODE_SUCCESS) { + return code; + } return TSDB_CODE_SUCCESS; } @@ -1844,7 +1863,10 @@ static int32_t translateToIso8601(SFunctionNode* pFunc, char* pErrBuf, int32_t l return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "Invalid timzone format"); } } else { // add default client timezone - addTimezoneParam(pFunc->pParameterList); + int32_t code = addTimezoneParam(pFunc->pParameterList); + if (code != TSDB_CODE_SUCCESS) { + return code; + } } // set result type @@ -1863,7 +1885,10 @@ static int32_t translateToUnixtimestamp(SFunctionNode* pFunc, char* pErrBuf, int // add database precision as param uint8_t dbPrec = pFunc->node.resType.precision; - addDbPrecisonParam(&pFunc->pParameterList, dbPrec); + int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec); + if (code != TSDB_CODE_SUCCESS) { + return code; + } pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; return TSDB_CODE_SUCCESS; @@ -1894,7 +1919,10 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_ "TIMETRUNCATE function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"); } - addDbPrecisonParam(&pFunc->pParameterList, dbPrec); + int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec); + if (code != TSDB_CODE_SUCCESS) { + return code; + } pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP}; @@ -1935,7 +1963,10 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le } } - addDbPrecisonParam(&pFunc->pParameterList, dbPrec); + int32_t code = addDbPrecisonParam(&pFunc->pParameterList, dbPrec); + if (code != TSDB_CODE_SUCCESS) { + return code; + } pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; return TSDB_CODE_SUCCESS; From 42dfe03e7d3d29b4fa08ca462c978419d4f46ad3 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 12/22] fix: coverity issues CID: 399518 --- source/libs/function/src/tpercentile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/function/src/tpercentile.c b/source/libs/function/src/tpercentile.c index 62c5e4b28b..c25d2d4a27 100644 --- a/source/libs/function/src/tpercentile.c +++ b/source/libs/function/src/tpercentile.c @@ -492,7 +492,7 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) int32_t groupId = getGroupId(pMemBucket->numOfSlots, i, pMemBucket->times - 1); SIDList list = taosHashGet(pMemBucket->groupPagesMap, &groupId, sizeof(groupId)); - assert(list->size > 0); + ASSERT(list != NULL && list->size > 0); for (int32_t f = 0; f < list->size; ++f) { SPageInfo *pgInfo = *(SPageInfo **)taosArrayGet(list, f); From cd0a051157a1df695146511f2cafcceb31a4d1b9 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 13/22] fix: coverity issues CID: 399671 --- source/libs/function/src/builtinsimpl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 874822106e..d3120c52e9 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -5371,7 +5371,7 @@ int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId); int32_t currentRow = pBlock->info.rows; - int32_t resIndex; + int32_t resIndex = -1; int32_t maxCount = 0; for (int32_t i = 0; i < pInfo->numOfPoints; ++i) { SModeItem* pItem = (SModeItem*)(pInfo->pItems + i * (sizeof(SModeItem) + pInfo->colBytes)); @@ -5381,6 +5381,7 @@ int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { } } + ASSERT(resIndex >= 0); SModeItem* pResItem = (SModeItem*)(pInfo->pItems + resIndex * (sizeof(SModeItem) + pInfo->colBytes)); colDataAppend(pCol, currentRow, pResItem->data, (maxCount == 0) ? true : false); From 23b7150deee004bc428baeaa9be25d1a6c02dc04 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 14/22] fix: coverity issues CID: 399845 --- source/libs/scalar/src/sclfunc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 339065633b..c20ff06c16 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1420,7 +1420,7 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { timeVal[k] = timeVal[k] * 1000; } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { - timeVal[k] = timeVal[k]; + timeVal[k] = timeVal[k] * 1; } else { hasNull = true; break; From 585577cef33f5a1fe312a17c4b2a1ae57f8e69b4 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 15/22] fix: coverity issues CID: 399989 --- source/libs/function/src/builtinsimpl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index d3120c52e9..3ed894fe8d 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -1872,7 +1872,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) { numOfElem += 1; pStddevRes->count += 1; pStddevRes->usum += plist[i]; - pStddevRes->quadraticISum += plist[i] * plist[i]; + pStddevRes->quadraticUSum += plist[i] * plist[i]; } break; @@ -1888,7 +1888,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) { numOfElem += 1; pStddevRes->count += 1; pStddevRes->usum += plist[i]; - pStddevRes->quadraticISum += plist[i] * plist[i]; + pStddevRes->quadraticUSum += plist[i] * plist[i]; } break; } @@ -1903,7 +1903,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) { numOfElem += 1; pStddevRes->count += 1; pStddevRes->usum += plist[i]; - pStddevRes->quadraticISum += plist[i] * plist[i]; + pStddevRes->quadraticUSum += plist[i] * plist[i]; } break; @@ -1919,7 +1919,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) { numOfElem += 1; pStddevRes->count += 1; pStddevRes->usum += plist[i]; - pStddevRes->quadraticISum += plist[i] * plist[i]; + pStddevRes->quadraticUSum += plist[i] * plist[i]; } break; } From c04ade786741b6d746e07a8e3132e9575010081a Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 24 Oct 2022 14:16:17 +0800 Subject: [PATCH 16/22] fix: coverity issues CID: 400109 --- source/libs/scalar/src/scalar.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 26adad27bc..37949d0ff0 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -1488,8 +1488,13 @@ static int32_t sclGetMinusOperatorResType(SOperatorNode *pOp) { } static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) { + if (pOp == NULL || pOp->pLeft == NULL || pOp->pRight == NULL) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType; SDataType rdt = ((SExprNode *)(pOp->pRight))->resType; + if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) || (TSDB_DATA_TYPE_TIMESTAMP == ldt.type && (IS_VAR_DATA_TYPE(rdt.type) || IS_FLOAT_TYPE(rdt.type))) || (TSDB_DATA_TYPE_TIMESTAMP == rdt.type && (IS_VAR_DATA_TYPE(ldt.type) || IS_FLOAT_TYPE(ldt.type)))) { @@ -1510,7 +1515,12 @@ static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) { } static int32_t sclGetCompOperatorResType(SOperatorNode *pOp) { + if (pOp == NULL || pOp->pLeft == NULL || pOp->pRight == NULL) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType; + if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) { ((SExprNode *)(pOp->pRight))->resType = ldt; } else if (nodesIsRegularOp(pOp)) { @@ -1526,8 +1536,13 @@ static int32_t sclGetCompOperatorResType(SOperatorNode *pOp) { } static int32_t sclGetJsonOperatorResType(SOperatorNode *pOp) { + if (pOp == NULL || pOp->pLeft == NULL || pOp->pRight == NULL) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } + SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType; SDataType rdt = ((SExprNode *)(pOp->pRight))->resType; + if (TSDB_DATA_TYPE_JSON != ldt.type || !IS_STR_DATA_TYPE(rdt.type)) { return TSDB_CODE_TSC_INVALID_OPERATION; } From caa88bc54d50ceb89762e2e3851fabe8da777350 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 25 Oct 2022 09:39:17 +0800 Subject: [PATCH 17/22] Revert "fix: coverity issues" This reverts commit aa4daf1770366d00dc35f36a6a6eedb1433458cd. --- source/common/src/tmsg.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 44a3f27983..94483b8a64 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -5954,7 +5954,6 @@ int32_t tDecodeSMqDataRsp(SDecoder *pDecoder, SMqDataRsp *pRsp) { if (pSW == NULL) return -1; if (tDecodeSSchemaWrapper(pDecoder, pSW) < 0) return -1; taosArrayPush(pRsp->blockSchema, &pSW); - taosMemoryFree(pSW); } if (pRsp->withTbName) { From 35b78f596ed823ce7efd60f640f9e07c8821e4fb Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 25 Oct 2022 09:42:26 +0800 Subject: [PATCH 18/22] Revert "Revert "fix: coverity issues"" This reverts commit caa88bc54d50ceb89762e2e3851fabe8da777350. --- source/common/src/tmsg.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 94483b8a64..44a3f27983 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -5954,6 +5954,7 @@ int32_t tDecodeSMqDataRsp(SDecoder *pDecoder, SMqDataRsp *pRsp) { if (pSW == NULL) return -1; if (tDecodeSSchemaWrapper(pDecoder, pSW) < 0) return -1; taosArrayPush(pRsp->blockSchema, &pSW); + taosMemoryFree(pSW); } if (pRsp->withTbName) { From 78d3a32f506f6ae21be0af5c43fd5884f8aef6e5 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 25 Oct 2022 09:43:25 +0800 Subject: [PATCH 19/22] Revert "fix: coverity issues" This reverts commit c2bff98311a1977a58d350506a0e91c815cc7912. --- source/common/src/trow.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/source/common/src/trow.c b/source/common/src/trow.c index 08a601909e..e1085ce5d8 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -948,10 +948,8 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp #ifdef TD_SUPPORT_BITMAP if (valType == TD_VTYPE_NORM) { terrno = TSDB_CODE_INVALID_PTR; - } else { - terrno = TSDB_CODE_INVALID_PARA; + return terrno; } - return terrno; #else TASSERT(0); terrno = TSDB_CODE_INVALID_PARA; @@ -1363,4 +1361,4 @@ void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColV *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, value); } -} +} \ No newline at end of file From b53a51e5e7371132a47b4799f395fbb42ee7cd64 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 25 Oct 2022 11:11:17 +0800 Subject: [PATCH 20/22] fix coverity --- source/libs/scalar/src/scalar.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 37949d0ff0..7c59c70f30 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -1515,15 +1515,21 @@ static int32_t sclGetMathOperatorResType(SOperatorNode *pOp) { } static int32_t sclGetCompOperatorResType(SOperatorNode *pOp) { - if (pOp == NULL || pOp->pLeft == NULL || pOp->pRight == NULL) { + if (pOp == NULL || pOp->pLeft == NULL) { return TSDB_CODE_TSC_INVALID_OPERATION; } SDataType ldt = ((SExprNode *)(pOp->pLeft))->resType; if (OP_TYPE_IN == pOp->opType || OP_TYPE_NOT_IN == pOp->opType) { + if (pOp->pRight == NULL) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } ((SExprNode *)(pOp->pRight))->resType = ldt; } else if (nodesIsRegularOp(pOp)) { + if (pOp->pRight == NULL) { + return TSDB_CODE_TSC_INVALID_OPERATION; + } SDataType rdt = ((SExprNode *)(pOp->pRight))->resType; if (!IS_VAR_DATA_TYPE(ldt.type) || QUERY_NODE_VALUE != nodeType(pOp->pRight) || (!IS_STR_DATA_TYPE(rdt.type) && (rdt.type != TSDB_DATA_TYPE_NULL))) { From d03058aff84f071c86a0aea751b478b7223bbd84 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 25 Oct 2022 11:11:17 +0800 Subject: [PATCH 21/22] fix coverity --- source/libs/function/src/builtinsimpl.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 88d820bc93..a093fe5116 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -5369,9 +5369,12 @@ int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { } } - ASSERT(resIndex >= 0); - SModeItem* pResItem = (SModeItem*)(pInfo->pItems + resIndex * (sizeof(SModeItem) + pInfo->colBytes)); - colDataAppend(pCol, currentRow, pResItem->data, (maxCount == 0) ? true : false); + if (maxCount != 0) { + SModeItem* pResItem = (SModeItem*)(pInfo->pItems + resIndex * (sizeof(SModeItem) + pInfo->colBytes)); + colDataAppend(pCol, currentRow, pResItem->data, false); + } else { + colDataAppendNULL(pCol, currentRow); + } return pResInfo->numOfRes; } From 600bb6ee77f3ca6dfd142f3f1b87ae41c26f438d Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 25 Oct 2022 11:11:17 +0800 Subject: [PATCH 22/22] fix coverity --- source/common/src/tmsg.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 6784b05e84..47a260c147 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -5988,7 +5988,6 @@ int32_t tDecodeSMqDataRsp(SDecoder *pDecoder, SMqDataRsp *pRsp) { if (pSW == NULL) return -1; if (tDecodeSSchemaWrapper(pDecoder, pSW) < 0) return -1; taosArrayPush(pRsp->blockSchema, &pSW); - taosMemoryFree(pSW); } if (pRsp->withTbName) {