From 02ea558db889568bbc797d054620d7b77133f3cf Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Mon, 15 Jul 2024 18:45:41 +0800 Subject: [PATCH 1/7] enh: return value: command --- source/libs/command/src/command.c | 121 ++++++++++++++++-------------- source/libs/command/src/explain.c | 13 ++-- 2 files changed, 73 insertions(+), 61 deletions(-) diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 9506e801c5..e528f61787 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -23,6 +23,15 @@ #include "tglobal.h" #include "tgrant.h" +#define COL_DATA_SET_VAL_AND_CHECK(pCol, rows, buf, isNull) \ + do { \ + int _code = colDataSetVal(pCol, rows, buf, isNull);\ + if (TSDB_CODE_SUCCESS != _code) { \ + terrno = _code; \ + return _code; \ + } \ + } while(0) + extern SConfig* tsCfg; static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRetrieveTableRsp** pRsp) { @@ -108,7 +117,7 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) { static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta, int8_t biMode) { int32_t blockCap = (biMode != 0) ? numOfRows + 1 : numOfRows; - blockDataEnsureCapacity(pBlock, blockCap); + QRY_ERR_RET(blockDataEnsureCapacity(pBlock, blockCap)); pBlock->info.rows = 0; // field @@ -138,11 +147,12 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, continue; } STR_TO_VARSTR(buf, pMeta->schema[i].name); - colDataSetVal(pCol1, pBlock->info.rows, buf, false); + COL_DATA_SET_VAL_AND_CHECK(pCol1, pBlock->info.rows, buf, false); + STR_TO_VARSTR(buf, tDataTypes[pMeta->schema[i].type].name); - colDataSetVal(pCol2, pBlock->info.rows, buf, false); + COL_DATA_SET_VAL_AND_CHECK(pCol2, pBlock->info.rows, buf, false); int32_t bytes = getSchemaBytes(pMeta->schema + i); - colDataSetVal(pCol3, pBlock->info.rows, (const char*)&bytes, false); + COL_DATA_SET_VAL_AND_CHECK(pCol3, pBlock->info.rows, (const char*)&bytes, false); if (TSDB_VIEW_TABLE != pMeta->tableType) { if (i >= pMeta->tableInfo.numOfColumns) { STR_TO_VARSTR(buf, "TAG"); @@ -155,22 +165,22 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, } else { STR_TO_VARSTR(buf, "VIEW COL"); } - colDataSetVal(pCol4, pBlock->info.rows, buf, false); + COL_DATA_SET_VAL_AND_CHECK(pCol4, pBlock->info.rows, buf, false); if (useCompress(pMeta->tableType) && pMeta->schemaExt) { if (i < pMeta->tableInfo.numOfColumns) { STR_TO_VARSTR(buf, columnEncodeStr(COMPRESS_L1_TYPE_U32(pMeta->schemaExt[i].compress))); - colDataSetVal(pCol5, pBlock->info.rows, buf, false); + COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false); STR_TO_VARSTR(buf, columnCompressStr(COMPRESS_L2_TYPE_U32(pMeta->schemaExt[i].compress))); - colDataSetVal(pCol6, pBlock->info.rows, buf, false); + COL_DATA_SET_VAL_AND_CHECK(pCol6, pBlock->info.rows, buf, false); STR_TO_VARSTR(buf, columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pMeta->schemaExt[i].compress))); - colDataSetVal(pCol7, pBlock->info.rows, buf, false); + COL_DATA_SET_VAL_AND_CHECK(pCol7, pBlock->info.rows, buf, false); } else { STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled"); - colDataSetVal(pCol5, pBlock->info.rows, buf, false); + COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false); STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled"); - colDataSetVal(pCol6, pBlock->info.rows, buf, false); + COL_DATA_SET_VAL_AND_CHECK(pCol6, pBlock->info.rows, buf, false); STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled"); - colDataSetVal(pCol7, pBlock->info.rows, buf, false); + COL_DATA_SET_VAL_AND_CHECK(pCol7, pBlock->info.rows, buf, false); } } @@ -180,13 +190,13 @@ static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, } if (pMeta->tableType == TSDB_SUPER_TABLE && biMode != 0) { STR_TO_VARSTR(buf, "tbname"); - colDataSetVal(pCol1, pBlock->info.rows, buf, false); + COL_DATA_SET_VAL_AND_CHECK(pCol1, pBlock->info.rows, buf, false); STR_TO_VARSTR(buf, "VARCHAR"); - colDataSetVal(pCol2, pBlock->info.rows, buf, false); + COL_DATA_SET_VAL_AND_CHECK(pCol2, pBlock->info.rows, buf, false); int32_t bytes = TSDB_TABLE_NAME_LEN - 1; - colDataSetVal(pCol3, pBlock->info.rows, (const char*)&bytes, false); + COL_DATA_SET_VAL_AND_CHECK(pCol3, pBlock->info.rows, (const char*)&bytes, false); STR_TO_VARSTR(buf, "TAG"); - colDataSetVal(pCol4, pBlock->info.rows, buf, false); + COL_DATA_SET_VAL_AND_CHECK(pCol4, pBlock->info.rows, buf, false); ++(pBlock->info.rows); } if (pBlock->info.rows <= 0) { @@ -264,13 +274,17 @@ int64_t getValOfDiffPrecision(int8_t unit, int64_t val) { return v; } -static char* buildRetension(SArray* pRetension) { +static int32_t buildRetension(SArray* pRetension, void **ppRetentions ) { size_t size = taosArrayGetSize(pRetension); if (size == 0) { - return NULL; + *ppRetentions = NULL; + return TSDB_CODE_SUCCESS; } char* p1 = taosMemoryCalloc(1, 100); + if(NULL == p1) { + return TSDB_CODE_OUT_OF_MEMORY; + } int32_t len = 0; for (int32_t i = 0; i < size; ++i) { @@ -288,7 +302,8 @@ static char* buildRetension(SArray* pRetension) { } } - return p1; + *ppRetentions = p1; + return TSDB_CODE_SUCCESS; } static const char* cacheModelStr(int8_t cacheModel) { @@ -319,14 +334,14 @@ static const char* encryptAlgorithmStr(int8_t encryptAlgorithm) { return TSDB_CACHE_MODEL_NONE_STR; } -static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) { - blockDataEnsureCapacity(pBlock, 1); +static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) { + QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1)); pBlock->info.rows = 1; SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0); char buf1[SHOW_CREATE_DB_RESULT_FIELD1_LEN] = {0}; STR_TO_VARSTR(buf1, dbName); - colDataSetVal(pCol1, 0, buf1, false); + COL_DATA_SET_VAL_AND_CHECK(pCol1, 0, buf1, false); SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1); char buf2[SHOW_CREATE_DB_RESULT_FIELD2_LEN] = {0}; @@ -347,7 +362,8 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, ch break; } - char* retentions = buildRetension(pCfg->pRetensions); + char* pRetentions = NULL; + QRY_ERR_RET(buildRetension(pCfg->pRetensions, &pRetentions)); int32_t dbFNameLen = strlen(dbFName); int32_t hashPrefix = 0; if (pCfg->hashPrefix > 0) { @@ -374,23 +390,25 @@ static void setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, ch pCfg->keepTimeOffset, encryptAlgorithmStr(pCfg->encryptAlgorithm), pCfg->s3ChunkSize, pCfg->s3KeepLocal, pCfg->s3Compact); - if (retentions) { - len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, " RETENTIONS %s", retentions); + if (pRetentions) { + len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, " RETENTIONS %s", pRetentions); } } - taosMemoryFree(retentions); + taosMemoryFree(pRetentions); (varDataLen(buf2)) = len; - colDataSetVal(pCol2, 0, buf2, false); + COL_DATA_SET_VAL_AND_CHECK(pCol2, 0, buf2, false); + + return TSDB_CODE_SUCCESS; } static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveTableRsp** pRsp) { SSDataBlock* pBlock = NULL; int32_t code = buildCreateDBResultDataBlock(&pBlock); if (TSDB_CODE_SUCCESS == code) { - setCreateDBResultIntoDataBlock(pBlock, pStmt->dbName, pStmt->dbFName, pStmt->pCfg); + code = setCreateDBResultIntoDataBlock(pBlock, pStmt->dbName, pStmt->dbFName, pStmt->pCfg); } if (TSDB_CODE_SUCCESS == code) { code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_DB_RESULT_COLS, pRsp); @@ -511,10 +529,7 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) { return TSDB_CODE_SUCCESS; } - int32_t code = tTagToValArray((const STag*)pCfg->pTags, &pTagVals); - if (code) { - return code; - } + QRY_ERR_RET(tTagToValArray((const STag*)pCfg->pTags, &pTagVals)); int16_t valueNum = taosArrayGetSize(pTagVals); int32_t num = 0; @@ -533,16 +548,15 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) { STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j); if (pSchema->colId > pTagVal->cid) { qError("tag value and column mismatch, schemaId:%d, valId:%d", pSchema->colId, pTagVal->cid); - taosArrayDestroy(pTagVals); - return TSDB_CODE_APP_ERROR; + TAOS_CHECK_ERRNO(TSDB_CODE_APP_ERROR); } else if (pSchema->colId == pTagVal->cid) { char type = pTagVal->type; int32_t tlen = 0; if (IS_VAR_DATA_TYPE(type)) { - dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, pTagVal->pData, pTagVal->nData, &tlen); + TAOS_CHECK_ERRNO(dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, pTagVal->pData, pTagVal->nData, &tlen)); } else { - dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, &pTagVal->i64, tDataTypes[type].bytes, &tlen); + TAOS_CHECK_ERRNO(dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, &pTagVal->i64, tDataTypes[type].bytes, &tlen)); } *len += tlen; j++; @@ -579,9 +593,10 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) { */ } +_exit: taosArrayDestroy(pTagVals); - return TSDB_CODE_SUCCESS; + return terrno; } void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg* pCfg) { @@ -646,14 +661,13 @@ void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg* } static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* pDbCfg, char* tbName, STableCfg* pCfg) { - int32_t code = 0; - blockDataEnsureCapacity(pBlock, 1); + QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1)); pBlock->info.rows = 1; SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0); char buf1[SHOW_CREATE_TB_RESULT_FIELD1_LEN] = {0}; STR_TO_VARSTR(buf1, tbName); - colDataSetVal(pCol1, 0, buf1, false); + QRY_ERR_RET(colDataSetVal(pCol1, 0, buf1, false)); SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1); char* buf2 = taosMemoryMalloc(SHOW_CREATE_TB_RESULT_FIELD2_LEN); @@ -675,11 +689,7 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p len += sprintf(buf2 + VARSTR_HEADER_SIZE, "CREATE TABLE `%s` USING `%s` (", tbName, pCfg->stbName); appendTagNameFields(buf2, &len, pCfg); len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ") TAGS ("); - code = appendTagValues(buf2, &len, pCfg); - if (code) { - taosMemoryFree(buf2); - return code; - } + TAOS_CHECK_ERRNO(appendTagValues(buf2, &len, pCfg)); len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ")"); appendTableOptions(buf2, &len, pDbCfg, pCfg); } else { @@ -691,29 +701,29 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p varDataLen(buf2) = (len > 65535) ? 65535 : len; - colDataSetVal(pCol2, 0, buf2, false); + TAOS_CHECK_ERRNO(colDataSetVal(pCol2, 0, buf2, false)); +_exit: taosMemoryFree(buf2); - return TSDB_CODE_SUCCESS; + return terrno; } static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreateViewStmt* pStmt) { int32_t code = 0; - blockDataEnsureCapacity(pBlock, 1); + QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1)); pBlock->info.rows = 1; SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0); char buf1[SHOW_CREATE_VIEW_RESULT_FIELD1_LEN + 1] = {0}; snprintf(varDataVal(buf1), TSDB_VIEW_FNAME_LEN + 4, "`%s`.`%s`", pStmt->dbName, pStmt->viewName); varDataSetLen(buf1, strlen(varDataVal(buf1))); - colDataSetVal(pCol1, 0, buf1, false); + QRY_ERR_RET(colDataSetVal(pCol1, 0, buf1, false)); SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1); char* buf2 = taosMemoryMalloc(SHOW_CREATE_VIEW_RESULT_FIELD2_LEN); if (NULL == buf2) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return terrno; + QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } SViewMeta* pMeta = pStmt->pViewMeta; @@ -722,8 +732,9 @@ static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreate pStmt->dbName, pStmt->viewName, pMeta->querySql); int32_t len = strlen(varDataVal(buf2)); varDataLen(buf2) = (len > 65535) ? 65535 : len; - colDataSetVal(pCol2, 0, buf2, false); + TAOS_CHECK_ERRNO(colDataSetVal(pCol2, 0, buf2, false)); +_exit: taosMemoryFree(buf2); return TSDB_CODE_SUCCESS; @@ -880,14 +891,14 @@ static int32_t createSelectResultDataBlock(SNodeList* pProjects, SSDataBlock** p infoData.info.type = pExpr->resType.type; infoData.info.bytes = pExpr->resType.bytes; } - blockDataAppendColInfo(pBlock, &infoData); + QRY_ERR_RET(blockDataAppendColInfo(pBlock, &infoData)); } *pOutput = pBlock; return TSDB_CODE_SUCCESS; } int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) { - blockDataEnsureCapacity(pBlock, 1); + QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1)); int32_t index = 0; SNode* pProj = NULL; @@ -896,9 +907,9 @@ int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) { return TSDB_CODE_PAR_INVALID_SELECTED_EXPR; } else { if (((SValueNode*)pProj)->isNull) { - colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true); + QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true)); } else { - colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, nodesGetValueFromNode((SValueNode*)pProj), false); + QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, nodesGetValueFromNode((SValueNode*)pProj), false)); } } } diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 2ac7e6ae3b..3b30e40470 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -1920,6 +1920,7 @@ _return: } int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { + int32_t code = 0; SExplainCtx *pCtx = (SExplainCtx *)ctx; int32_t rowNum = taosArrayGetSize(pCtx->rows); if (rowNum <= 0) { @@ -1929,14 +1930,14 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { SSDataBlock *pBlock = createDataBlock(); SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, TSDB_EXPLAIN_RESULT_ROW_SIZE, 1); - blockDataAppendColInfo(pBlock, &infoData); - blockDataEnsureCapacity(pBlock, rowNum); + QRY_ERR_JRET(blockDataAppendColInfo(pBlock, &infoData)); + QRY_ERR_JRET(blockDataEnsureCapacity(pBlock, rowNum)); SColumnInfoData *pInfoData = taosArrayGet(pBlock->pDataBlock, 0); for (int32_t i = 0; i < rowNum; ++i) { SQueryExplainRowInfo *row = taosArrayGet(pCtx->rows, i); - colDataSetVal(pInfoData, i, row->buf, false); + QRY_ERR_JRET(colDataSetVal(pInfoData, i, row->buf, false)); } pBlock->info.rows = rowNum; @@ -1946,8 +1947,7 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, rspSize); if (NULL == rsp) { qError("malloc SRetrieveTableRsp failed, size:%d", rspSize); - blockDataDestroy(pBlock); - QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); } rsp->completed = 1; @@ -1961,10 +1961,11 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { SET_PAYLOAD_LEN(rsp->data, len, len); +_return: blockDataDestroy(pBlock); *pRsp = rsp; - return TSDB_CODE_SUCCESS; + QRY_RET(code); } int32_t qExplainPrepareCtx(SQueryPlan *pDag, SExplainCtx **pCtx) { From 1583fbb40d30265a10d9e68df6801c96682a0115 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Mon, 15 Jul 2024 18:55:18 +0800 Subject: [PATCH 2/7] fix: build error --- source/libs/command/src/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index e528f61787..4cd87b139e 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -274,7 +274,7 @@ int64_t getValOfDiffPrecision(int8_t unit, int64_t val) { return v; } -static int32_t buildRetension(SArray* pRetension, void **ppRetentions ) { +static int32_t buildRetension(SArray* pRetension, char **ppRetentions ) { size_t size = taosArrayGetSize(pRetension); if (size == 0) { *ppRetentions = NULL; From 010a1da48294734f1c4f6febd847749219d6881a Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Tue, 16 Jul 2024 09:40:19 +0800 Subject: [PATCH 3/7] return value: querymsg.c --- source/client/src/clientEnv.c | 6 +++++- source/client/src/clientRawBlockWrite.c | 13 +++++++++++-- source/libs/command/src/command.c | 3 +-- source/libs/qcom/src/querymsg.c | 6 ++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 18907ede5d..7d737fbb8e 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -885,7 +885,11 @@ void taos_init_imp(void) { taosSetCoreDump(true); #endif - initTaskQueue(); + if (initTaskQueue() != 0){ + tscInitRes = -1; + tscError("failed to init task queue"); + return; + } fmFuncMgtInit(); nodesInitAllocatorSet(); diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index 2fabf01ef4..9e1ff6e5e5 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -460,8 +460,14 @@ static void buildChildElement(cJSON* json, SVCreateTbReq* pCreateReq) { } else { buf = taosMemoryCalloc(pTagVal->nData + 3, 1); } + RAW_NULL_CHECK(buf); - RAW_RETURN_CHECK(dataConverToStr(buf, pTagVal->type, pTagVal->pData, pTagVal->nData, NULL)); + if (!buf) goto end; + if(dataConverToStr(buf, pTagVal->type, pTagVal->pData, pTagVal->nData, NULL) != TSDB_CODE_SUCCESS) { + taosMemoryFree(buf); + goto end; + } + tvalue = cJSON_CreateString(buf); RAW_NULL_CHECK(tvalue); taosMemoryFree(buf); @@ -729,7 +735,10 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) { buf = taosMemoryCalloc(vAlterTbReq.nTagVal + 3, 1); } RAW_NULL_CHECK(buf); - RAW_RETURN_CHECK(dataConverToStr(buf, vAlterTbReq.tagType, vAlterTbReq.pTagVal, vAlterTbReq.nTagVal, NULL)); + if(dataConverToStr(buf, vAlterTbReq.tagType, vAlterTbReq.pTagVal, vAlterTbReq.nTagVal, NULL) != TSDB_CODE_SUCCESS) { + taosMemoryFree(buf); + goto end; + } } cJSON* colValue = cJSON_CreateString(buf); diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 4cd87b139e..8b2415128a 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -672,8 +672,7 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1); char* buf2 = taosMemoryMalloc(SHOW_CREATE_TB_RESULT_FIELD2_LEN); if (NULL == buf2) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return terrno; + QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } int32_t len = 0; diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index b13919e5e1..1f5b6315ba 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -713,6 +713,9 @@ int32_t queryProcessGetTbCfgRsp(void *output, char *msg, int32_t msgSize) { } STableCfgRsp *out = taosMemoryCalloc(1, sizeof(STableCfgRsp)); + if(out == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } if (tDeserializeSTableCfgRsp(msg, msgSize, out) != 0) { qError("tDeserializeSTableCfgRsp failed, msgSize:%d", msgSize); tFreeSTableCfgRsp(out); @@ -731,6 +734,9 @@ int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) { } SViewMetaRsp *out = taosMemoryCalloc(1, sizeof(SViewMetaRsp)); + if (out == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } if (tDeserializeSViewMetaRsp(msg, msgSize, out) != 0) { qError("tDeserializeSViewMetaRsp failed, msgSize:%d", msgSize); tFreeSViewMetaRsp(out); From 200fd4738fb7af5d7ec0efd82e425befdf4efe24 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Tue, 16 Jul 2024 11:50:52 +0800 Subject: [PATCH 4/7] array push --- source/libs/command/src/command.c | 47 ++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 8b2415128a..43091b38ad 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -14,11 +14,14 @@ */ #include "command.h" +#include #include "catalog.h" #include "commandInt.h" #include "scheduler.h" #include "systable.h" #include "taosdef.h" +#include "taoserror.h" +#include "tarray.h" #include "tdatablock.h" #include "tglobal.h" #include "tgrant.h" @@ -109,7 +112,7 @@ static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) { if (TSDB_CODE_SUCCESS == code) { *pOutput = pBlock; } else { - blockDataDestroy(pBlock); + (void)blockDataDestroy(pBlock); } return code; } @@ -222,7 +225,7 @@ static int32_t execDescribe(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp); } } - blockDataDestroy(pBlock); + (void)blockDataDestroy(pBlock); return code; } @@ -244,7 +247,7 @@ static int32_t buildCreateDBResultDataBlock(SSDataBlock** pOutput) { if (TSDB_CODE_SUCCESS == code) { *pOutput = pBlock; } else { - blockDataDestroy(pBlock); + (void)blockDataDestroy(pBlock); } return code; } @@ -413,7 +416,7 @@ static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveT if (TSDB_CODE_SUCCESS == code) { code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_DB_RESULT_COLS, pRsp); } - blockDataDestroy(pBlock); + (void)blockDataDestroy(pBlock); return code; } @@ -433,7 +436,7 @@ static int32_t buildCreateTbResultDataBlock(SSDataBlock** pOutput) { if (TSDB_CODE_SUCCESS == code) { *pOutput = pBlock; } else { - blockDataDestroy(pBlock); + (void)blockDataDestroy(pBlock); } return code; } @@ -454,7 +457,7 @@ static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) { if (TSDB_CODE_SUCCESS == code) { *pOutput = pBlock; } else { - blockDataDestroy(pBlock); + (void)blockDataDestroy(pBlock); } return code; } @@ -748,7 +751,7 @@ static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRs if (TSDB_CODE_SUCCESS == code) { code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_TB_RESULT_COLS, pRsp); } - blockDataDestroy(pBlock); + (void)blockDataDestroy(pBlock); return code; } @@ -841,23 +844,39 @@ static int32_t buildLocalVariablesResultDataBlock(SSDataBlock** pOutput) { pBlock->info.hasVarCol = true; pBlock->pDataBlock = taosArrayInit(SHOW_LOCAL_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData)); + if (NULL == pBlock->pDataBlock) { + taosMemoryFree(pBlock); + return TSDB_CODE_OUT_OF_MEMORY; + } SColumnInfoData infoData = {0}; infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN; - taosArrayPush(pBlock->pDataBlock, &infoData); + if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { + goto _exit; + } infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN; - taosArrayPush(pBlock->pDataBlock, &infoData); + if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { + goto _exit; + } infoData.info.type = TSDB_DATA_TYPE_VARCHAR; infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD3_LEN; - taosArrayPush(pBlock->pDataBlock, &infoData); + if(taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) { + goto _exit; + } *pOutput = pBlock; - return TSDB_CODE_SUCCESS; + +_exit: + if(terrno != TSDB_CODE_SUCCESS) { + taosMemoryFree(pBlock); + taosArrayDestroy(pBlock->pDataBlock); + } + return terrno; } static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) { @@ -869,7 +888,7 @@ static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) { if (TSDB_CODE_SUCCESS == code) { code = buildRetrieveTableRsp(pBlock, SHOW_LOCAL_VARIABLES_RESULT_COLS, pRsp); } - blockDataDestroy(pBlock); + (void)blockDataDestroy(pBlock); return code; } @@ -926,7 +945,7 @@ static int32_t execSelectWithoutFrom(SSelectStmt* pSelect, SRetrieveTableRsp** p if (TSDB_CODE_SUCCESS == code) { code = buildRetrieveTableRsp(pBlock, LIST_LENGTH(pSelect->pProjectionList), pRsp); } - blockDataDestroy(pBlock); + (void)blockDataDestroy(pBlock); return code; } @@ -939,7 +958,7 @@ static int32_t execShowCreateView(SShowCreateViewStmt* pStmt, SRetrieveTableRsp* if (TSDB_CODE_SUCCESS == code) { code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_VIEW_RESULT_COLS, pRsp); } - blockDataDestroy(pBlock); + (void)blockDataDestroy(pBlock); return code; } From ebec7c928bd9b2cb154bd6b91af7725846bbe6b2 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Tue, 16 Jul 2024 13:58:58 +0800 Subject: [PATCH 5/7] array push --- source/libs/command/src/explain.c | 29 +++++++++++------------ source/libs/qcom/src/querymsg.c | 39 ++++++++++++++++++------------- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 3b30e40470..6aadb68da5 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -199,7 +199,7 @@ int32_t qExplainGenerateResNodeExecInfo(SPhysiNode *pNode, SArray **pExecInfo, S return TSDB_CODE_APP_ERROR; } - taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx); + if(taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx) == NULL) return terrno; } else { for (int32_t i = 0; i < group->nodeNum; ++i) { rsp = taosArrayGet(group->nodeExecInfo, i); @@ -208,7 +208,7 @@ int32_t qExplainGenerateResNodeExecInfo(SPhysiNode *pNode, SArray **pExecInfo, S return TSDB_CODE_APP_ERROR; } - taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx); + if(taosArrayPush(*pExecInfo, rsp->subplanInfo + group->physiPlanExecIdx) == NULL) return terrno; } } @@ -2100,32 +2100,26 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t group->nodeExecInfo = taosArrayInit(group->nodeNum, sizeof(SExplainRsp)); if (NULL == group->nodeExecInfo) { qError("taosArrayInit %d explainExecInfo failed", group->nodeNum); - tFreeSExplainRsp(pRspMsg); - taosWUnLockLatch(&group->lock); - - QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; } group->physiPlanExecNum = pRspMsg->numOfPlans; } else if (taosArrayGetSize(group->nodeExecInfo) >= group->nodeNum) { qError("group execInfo already full, size:%d, nodeNum:%d", (int32_t)taosArrayGetSize(group->nodeExecInfo), group->nodeNum); - tFreeSExplainRsp(pRspMsg); - taosWUnLockLatch(&group->lock); - - QRY_ERR_RET(TSDB_CODE_APP_ERROR); + terrno = TSDB_CODE_APP_ERROR; + goto _exit; } if (group->physiPlanExecNum != pRspMsg->numOfPlans) { qError("physiPlanExecNum %d mismatch with others %d in group %d", pRspMsg->numOfPlans, group->physiPlanExecNum, groupId); - tFreeSExplainRsp(pRspMsg); - taosWUnLockLatch(&group->lock); - - QRY_ERR_RET(TSDB_CODE_APP_ERROR); + terrno = TSDB_CODE_APP_ERROR; + goto _exit; } - taosArrayPush(group->nodeExecInfo, pRspMsg); + if(taosArrayPush(group->nodeExecInfo, pRspMsg) == NULL) goto _exit; groupDone = (taosArrayGetSize(group->nodeExecInfo) >= group->nodeNum); @@ -2141,6 +2135,11 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t } return TSDB_CODE_SUCCESS; + +_exit: + tFreeSExplainRsp(pRspMsg); + taosWUnLockLatch(&group->lock); + return terrno; } int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp) { diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 1f5b6315ba..fdb5f2d9c1 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -16,6 +16,7 @@ #include "query.h" #include "queryInt.h" #include "systable.h" +#include "taoserror.h" #include "tmsg.h" #include "trpc.h" @@ -85,7 +86,7 @@ int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int3 int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq); void *pBuf = (*mallcFp)(bufLen); - tSerializeSTableInfoReq(pBuf, bufLen, &infoReq); + (void)tSerializeSTableInfoReq(pBuf, bufLen, &infoReq); *msg = pBuf; *msgLen = bufLen; @@ -109,7 +110,7 @@ int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *ms int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq); void *pBuf = (*mallcFp)(bufLen); - tSerializeSUseDbReq(pBuf, bufLen, &usedbReq); + (void)tSerializeSUseDbReq(pBuf, bufLen, &usedbReq); *msg = pBuf; *msgLen = bufLen; @@ -127,7 +128,7 @@ int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t bufLen = tSerializeSQnodeListReq(NULL, 0, &qnodeListReq); void *pBuf = (*mallcFp)(bufLen); - tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq); + (void)tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq); *msg = pBuf; *msgLen = bufLen; @@ -145,7 +146,7 @@ int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t bufLen = tSerializeSDnodeListReq(NULL, 0, &dnodeListReq); void *pBuf = (*mallcFp)(bufLen); - tSerializeSDnodeListReq(pBuf, bufLen, &dnodeListReq); + (void)tSerializeSDnodeListReq(pBuf, bufLen, &dnodeListReq); *msg = pBuf; *msgLen = bufLen; @@ -162,7 +163,7 @@ int32_t queryBuildGetSerVerMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t bufLen = tSerializeSServerVerReq(NULL, 0, &req); void *pBuf = (*mallcFp)(bufLen); - tSerializeSServerVerReq(pBuf, bufLen, &req); + (void)tSerializeSServerVerReq(pBuf, bufLen, &req); *msg = pBuf; *msgLen = bufLen; @@ -180,7 +181,7 @@ int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t bufLen = tSerializeSDbCfgReq(NULL, 0, &dbCfgReq); void *pBuf = (*mallcFp)(bufLen); - tSerializeSDbCfgReq(pBuf, bufLen, &dbCfgReq); + (void)tSerializeSDbCfgReq(pBuf, bufLen, &dbCfgReq); *msg = pBuf; *msgLen = bufLen; @@ -198,7 +199,7 @@ int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t bufLen = tSerializeSUserIndexReq(NULL, 0, &indexReq); void *pBuf = (*mallcFp)(bufLen); - tSerializeSUserIndexReq(pBuf, bufLen, &indexReq); + (void)tSerializeSUserIndexReq(pBuf, bufLen, &indexReq); *msg = pBuf; *msgLen = bufLen; @@ -216,11 +217,17 @@ int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int3 funcReq.numOfFuncs = 1; funcReq.ignoreCodeComment = true; funcReq.pFuncNames = taosArrayInit(1, strlen(input) + 1); - taosArrayPush(funcReq.pFuncNames, input); + if (NULL == funcReq.pFuncNames) { + return TSDB_CODE_OUT_OF_MEMORY; + } + if (taosArrayPush(funcReq.pFuncNames, input) == NULL) { + taosArrayDestroy(funcReq.pFuncNames); + return terrno; + } int32_t bufLen = tSerializeSRetrieveFuncReq(NULL, 0, &funcReq); void *pBuf = (*mallcFp)(bufLen); - tSerializeSRetrieveFuncReq(pBuf, bufLen, &funcReq); + (void)tSerializeSRetrieveFuncReq(pBuf, bufLen, &funcReq); taosArrayDestroy(funcReq.pFuncNames); @@ -240,7 +247,7 @@ int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32 int32_t bufLen = tSerializeSGetUserAuthReq(NULL, 0, &req); void *pBuf = (*mallcFp)(bufLen); - tSerializeSGetUserAuthReq(pBuf, bufLen, &req); + (void)tSerializeSGetUserAuthReq(pBuf, bufLen, &req); *msg = pBuf; *msgLen = bufLen; @@ -258,7 +265,7 @@ int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_ int32_t bufLen = tSerializeSTableIndexReq(NULL, 0, &indexReq); void *pBuf = (*mallcFp)(bufLen); - tSerializeSTableIndexReq(pBuf, bufLen, &indexReq); + (void)tSerializeSTableIndexReq(pBuf, bufLen, &indexReq); *msg = pBuf; *msgLen = bufLen; @@ -279,7 +286,7 @@ int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t bufLen = tSerializeSTableCfgReq(NULL, 0, &cfgReq); void *pBuf = (*mallcFp)(bufLen); - tSerializeSTableCfgReq(pBuf, bufLen, &cfgReq); + (void)tSerializeSTableCfgReq(pBuf, bufLen, &cfgReq); *msg = pBuf; *msgLen = bufLen; @@ -297,7 +304,7 @@ int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32 int32_t bufLen = tSerializeSViewMetaReq(NULL, 0, &req); void *pBuf = (*mallcFp)(bufLen); - tSerializeSViewMetaReq(pBuf, bufLen, &req); + (void)tSerializeSViewMetaReq(pBuf, bufLen, &req); *msg = pBuf; *msgLen = bufLen; @@ -316,7 +323,7 @@ int32_t queryBuildGetTableTSMAMsg(void *input, char **msg, int32_t msgSize, int3 int32_t bufLen = tSerializeTableTSMAInfoReq(NULL, 0, &req); void * pBuf = (*mallcFp)(bufLen); - tSerializeTableTSMAInfoReq(pBuf, bufLen, &req); + (void)tSerializeTableTSMAInfoReq(pBuf, bufLen, &req); *msg = pBuf; *msgLen = bufLen; @@ -335,7 +342,7 @@ int32_t queryBuildGetTSMAMsg(void *input, char **msg, int32_t msgSize, int32_t * int32_t bufLen = tSerializeTableTSMAInfoReq(NULL, 0, &req); void * pBuf = (*mallcFp)(bufLen); - tSerializeTableTSMAInfoReq(pBuf, bufLen, &req); + (void)tSerializeTableTSMAInfoReq(pBuf, bufLen, &req); *msg = pBuf; *msgLen = bufLen; @@ -350,7 +357,7 @@ int32_t queryBuildGetStreamProgressMsg(void* input, char** msg, int32_t msgSize, int32_t len = tSerializeStreamProgressReq(NULL, 0, input); void* pBuf = (*mallcFp)(len); - tSerializeStreamProgressReq(pBuf, len, input); + (void)tSerializeStreamProgressReq(pBuf, len, input); *msg = pBuf; *msgLen = len; From 99dcaaff217ae929a70c94d6bd58ce0c2aed6ab5 Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Tue, 16 Jul 2024 15:52:06 +0800 Subject: [PATCH 6/7] build on windows --- source/libs/command/src/command.c | 5 +---- source/libs/qcom/src/querymsg.c | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 43091b38ad..136e1d4ae1 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -14,14 +14,11 @@ */ #include "command.h" -#include #include "catalog.h" #include "commandInt.h" #include "scheduler.h" #include "systable.h" #include "taosdef.h" -#include "taoserror.h" -#include "tarray.h" #include "tdatablock.h" #include "tglobal.h" #include "tgrant.h" @@ -739,7 +736,7 @@ static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreate _exit: taosMemoryFree(buf2); - return TSDB_CODE_SUCCESS; + return terrno; } static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) { diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index fdb5f2d9c1..c803eb2cf8 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -16,7 +16,6 @@ #include "query.h" #include "queryInt.h" #include "systable.h" -#include "taoserror.h" #include "tmsg.h" #include "trpc.h" From e86189d9ea783d63ab6c90ed631336e1bab56d9c Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Sun, 21 Jul 2024 18:57:08 +0800 Subject: [PATCH 7/7] check serialize result --- source/libs/command/src/command.c | 28 +++++++----- source/libs/command/src/explain.c | 20 ++++---- source/libs/qcom/src/querymsg.c | 76 ++++++++++++++++++++++++------- 3 files changed, 88 insertions(+), 36 deletions(-) diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 136e1d4ae1..07409b1411 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -512,6 +512,7 @@ void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) { } int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) { + int32_t code = TSDB_CODE_SUCCESS; SArray* pTagVals = NULL; STag* pTag = (STag*)pCfg->pTags; @@ -530,7 +531,6 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) { } QRY_ERR_RET(tTagToValArray((const STag*)pCfg->pTags, &pTagVals)); - int16_t valueNum = taosArrayGetSize(pTagVals); int32_t num = 0; int32_t j = 0; @@ -548,15 +548,18 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) { STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j); if (pSchema->colId > pTagVal->cid) { qError("tag value and column mismatch, schemaId:%d, valId:%d", pSchema->colId, pTagVal->cid); - TAOS_CHECK_ERRNO(TSDB_CODE_APP_ERROR); + code = TSDB_CODE_APP_ERROR; + TAOS_CHECK_ERRNO(code); } else if (pSchema->colId == pTagVal->cid) { char type = pTagVal->type; int32_t tlen = 0; if (IS_VAR_DATA_TYPE(type)) { - TAOS_CHECK_ERRNO(dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, pTagVal->pData, pTagVal->nData, &tlen)); + code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, pTagVal->pData, pTagVal->nData, &tlen); + TAOS_CHECK_ERRNO(code); } else { - TAOS_CHECK_ERRNO(dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, &pTagVal->i64, tDataTypes[type].bytes, &tlen)); + code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, &pTagVal->i64, tDataTypes[type].bytes, &tlen); + TAOS_CHECK_ERRNO(code); } *len += tlen; j++; @@ -596,7 +599,7 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) { _exit: taosArrayDestroy(pTagVals); - return terrno; + return code; } void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg* pCfg) { @@ -661,6 +664,7 @@ void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg* } static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* pDbCfg, char* tbName, STableCfg* pCfg) { + int32_t code = TSDB_CODE_SUCCESS; QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1)); pBlock->info.rows = 1; @@ -688,7 +692,8 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p len += sprintf(buf2 + VARSTR_HEADER_SIZE, "CREATE TABLE `%s` USING `%s` (", tbName, pCfg->stbName); appendTagNameFields(buf2, &len, pCfg); len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ") TAGS ("); - TAOS_CHECK_ERRNO(appendTagValues(buf2, &len, pCfg)); + code = appendTagValues(buf2, &len, pCfg); + TAOS_CHECK_ERRNO(code); len += sprintf(buf2 + VARSTR_HEADER_SIZE + len, ")"); appendTableOptions(buf2, &len, pDbCfg, pCfg); } else { @@ -700,12 +705,13 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p varDataLen(buf2) = (len > 65535) ? 65535 : len; - TAOS_CHECK_ERRNO(colDataSetVal(pCol2, 0, buf2, false)); + code = colDataSetVal(pCol2, 0, buf2, false); + TAOS_CHECK_ERRNO(code); _exit: taosMemoryFree(buf2); - return terrno; + return code; } static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreateViewStmt* pStmt) { @@ -731,12 +737,10 @@ static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreate pStmt->dbName, pStmt->viewName, pMeta->querySql); int32_t len = strlen(varDataVal(buf2)); varDataLen(buf2) = (len > 65535) ? 65535 : len; - TAOS_CHECK_ERRNO(colDataSetVal(pCol2, 0, buf2, false)); - -_exit: + code = colDataSetVal(pCol2, 0, buf2, false); taosMemoryFree(buf2); - return terrno; + return code; } static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp) { diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 6aadb68da5..843e3ee734 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -2100,26 +2100,30 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t group->nodeExecInfo = taosArrayInit(group->nodeNum, sizeof(SExplainRsp)); if (NULL == group->nodeExecInfo) { qError("taosArrayInit %d explainExecInfo failed", group->nodeNum); - terrno = TSDB_CODE_OUT_OF_MEMORY; - goto _exit; + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_CHECK_ERRNO(code); } group->physiPlanExecNum = pRspMsg->numOfPlans; } else if (taosArrayGetSize(group->nodeExecInfo) >= group->nodeNum) { qError("group execInfo already full, size:%d, nodeNum:%d", (int32_t)taosArrayGetSize(group->nodeExecInfo), group->nodeNum); - terrno = TSDB_CODE_APP_ERROR; - goto _exit; + code = TSDB_CODE_APP_ERROR; + TAOS_CHECK_ERRNO(code); } if (group->physiPlanExecNum != pRspMsg->numOfPlans) { qError("physiPlanExecNum %d mismatch with others %d in group %d", pRspMsg->numOfPlans, group->physiPlanExecNum, groupId); - terrno = TSDB_CODE_APP_ERROR; - goto _exit; + code = TSDB_CODE_APP_ERROR; + TAOS_CHECK_ERRNO(code); } - if(taosArrayPush(group->nodeExecInfo, pRspMsg) == NULL) goto _exit; + if(taosArrayPush(group->nodeExecInfo, pRspMsg) == NULL) + { + code = TSDB_CODE_OUT_OF_MEMORY; + TAOS_CHECK_ERRNO(code); + } groupDone = (taosArrayGetSize(group->nodeExecInfo) >= group->nodeNum); @@ -2139,7 +2143,7 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t _exit: tFreeSExplainRsp(pRspMsg); taosWUnLockLatch(&group->lock); - return terrno; + return code; } int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp) { diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index c803eb2cf8..e8deed1df9 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -85,7 +85,10 @@ int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int3 int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq); void *pBuf = (*mallcFp)(bufLen); - (void)tSerializeSTableInfoReq(pBuf, bufLen, &infoReq); + if(tSerializeSTableInfoReq(pBuf, bufLen, &infoReq) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -109,7 +112,10 @@ int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *ms int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq); void *pBuf = (*mallcFp)(bufLen); - (void)tSerializeSUseDbReq(pBuf, bufLen, &usedbReq); + if(tSerializeSUseDbReq(pBuf, bufLen, &usedbReq) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -127,7 +133,10 @@ int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t bufLen = tSerializeSQnodeListReq(NULL, 0, &qnodeListReq); void *pBuf = (*mallcFp)(bufLen); - (void)tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq); + if(tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -145,7 +154,10 @@ int32_t queryBuildDnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t bufLen = tSerializeSDnodeListReq(NULL, 0, &dnodeListReq); void *pBuf = (*mallcFp)(bufLen); - (void)tSerializeSDnodeListReq(pBuf, bufLen, &dnodeListReq); + if(tSerializeSDnodeListReq(pBuf, bufLen, &dnodeListReq) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -162,7 +174,10 @@ int32_t queryBuildGetSerVerMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t bufLen = tSerializeSServerVerReq(NULL, 0, &req); void *pBuf = (*mallcFp)(bufLen); - (void)tSerializeSServerVerReq(pBuf, bufLen, &req); + if(tSerializeSServerVerReq(pBuf, bufLen, &req) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -180,7 +195,10 @@ int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t bufLen = tSerializeSDbCfgReq(NULL, 0, &dbCfgReq); void *pBuf = (*mallcFp)(bufLen); - (void)tSerializeSDbCfgReq(pBuf, bufLen, &dbCfgReq); + if(tSerializeSDbCfgReq(pBuf, bufLen, &dbCfgReq) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -198,7 +216,10 @@ int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t bufLen = tSerializeSUserIndexReq(NULL, 0, &indexReq); void *pBuf = (*mallcFp)(bufLen); - (void)tSerializeSUserIndexReq(pBuf, bufLen, &indexReq); + if(tSerializeSUserIndexReq(pBuf, bufLen, &indexReq) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -221,12 +242,15 @@ int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int3 } if (taosArrayPush(funcReq.pFuncNames, input) == NULL) { taosArrayDestroy(funcReq.pFuncNames); - return terrno; + return TSDB_CODE_OUT_OF_MEMORY; } int32_t bufLen = tSerializeSRetrieveFuncReq(NULL, 0, &funcReq); void *pBuf = (*mallcFp)(bufLen); - (void)tSerializeSRetrieveFuncReq(pBuf, bufLen, &funcReq); + if(tSerializeSRetrieveFuncReq(pBuf, bufLen, &funcReq) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } taosArrayDestroy(funcReq.pFuncNames); @@ -246,7 +270,9 @@ int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32 int32_t bufLen = tSerializeSGetUserAuthReq(NULL, 0, &req); void *pBuf = (*mallcFp)(bufLen); - (void)tSerializeSGetUserAuthReq(pBuf, bufLen, &req); + if (tSerializeSGetUserAuthReq(pBuf, bufLen, &req) < 0) { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -264,7 +290,10 @@ int32_t queryBuildGetTbIndexMsg(void *input, char **msg, int32_t msgSize, int32_ int32_t bufLen = tSerializeSTableIndexReq(NULL, 0, &indexReq); void *pBuf = (*mallcFp)(bufLen); - (void)tSerializeSTableIndexReq(pBuf, bufLen, &indexReq); + if(tSerializeSTableIndexReq(pBuf, bufLen, &indexReq) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -285,7 +314,10 @@ int32_t queryBuildGetTbCfgMsg(void *input, char **msg, int32_t msgSize, int32_t int32_t bufLen = tSerializeSTableCfgReq(NULL, 0, &cfgReq); void *pBuf = (*mallcFp)(bufLen); - (void)tSerializeSTableCfgReq(pBuf, bufLen, &cfgReq); + if(tSerializeSTableCfgReq(pBuf, bufLen, &cfgReq) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -303,7 +335,10 @@ int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32 int32_t bufLen = tSerializeSViewMetaReq(NULL, 0, &req); void *pBuf = (*mallcFp)(bufLen); - (void)tSerializeSViewMetaReq(pBuf, bufLen, &req); + if(tSerializeSViewMetaReq(pBuf, bufLen, &req) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -322,7 +357,10 @@ int32_t queryBuildGetTableTSMAMsg(void *input, char **msg, int32_t msgSize, int3 int32_t bufLen = tSerializeTableTSMAInfoReq(NULL, 0, &req); void * pBuf = (*mallcFp)(bufLen); - (void)tSerializeTableTSMAInfoReq(pBuf, bufLen, &req); + if(tSerializeTableTSMAInfoReq(pBuf, bufLen, &req) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -341,7 +379,10 @@ int32_t queryBuildGetTSMAMsg(void *input, char **msg, int32_t msgSize, int32_t * int32_t bufLen = tSerializeTableTSMAInfoReq(NULL, 0, &req); void * pBuf = (*mallcFp)(bufLen); - (void)tSerializeTableTSMAInfoReq(pBuf, bufLen, &req); + if(tSerializeTableTSMAInfoReq(pBuf, bufLen, &req) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = bufLen; @@ -356,7 +397,10 @@ int32_t queryBuildGetStreamProgressMsg(void* input, char** msg, int32_t msgSize, int32_t len = tSerializeStreamProgressReq(NULL, 0, input); void* pBuf = (*mallcFp)(len); - (void)tSerializeStreamProgressReq(pBuf, len, input); + if(tSerializeStreamProgressReq(pBuf, len, input) < 0) + { + return TSDB_CODE_TSC_INVALID_INPUT; + } *msg = pBuf; *msgLen = len;