fix: buff size
This commit is contained in:
parent
7f2a2cfbd0
commit
e88a8317af
|
@ -29,6 +29,6 @@ int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs)
|
|||
int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp);
|
||||
int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp);
|
||||
void qExplainFreeCtx(SExplainCtx *pCtx);
|
||||
int32_t formatDurationOrKeep(char* buffer, int32_t timeInMinutes);
|
||||
int32_t formatDurationOrKeep(char* buffer, int64_t bufSize, int32_t timeInMinutes);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -336,7 +336,7 @@ char* jobTaskStatusStr(int32_t status);
|
|||
SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name);
|
||||
|
||||
void destroyQueryExecRes(SExecResult* pRes);
|
||||
int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t* len);
|
||||
int32_t dataConverToStr(char* str, int64_t capacity, int type, void* buf, int32_t bufSize, int32_t* len);
|
||||
void parseTagDatatoJson(void* p, char** jsonStr);
|
||||
int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst);
|
||||
void getColumnTypeFromMeta(STableMeta* pMeta, char* pName, ETableColumnType* pType);
|
||||
|
|
|
@ -458,17 +458,17 @@ static void buildChildElement(cJSON* json, SVCreateTbReq* pCreateReq) {
|
|||
cJSON* tvalue = NULL;
|
||||
if (IS_VAR_DATA_TYPE(pTagVal->type)) {
|
||||
char* buf = NULL;
|
||||
int64_t bufSize = 0;
|
||||
if (pTagVal->type == TSDB_DATA_TYPE_VARBINARY) {
|
||||
buf = taosMemoryCalloc(pTagVal->nData * 2 + 2 + 3, 1);
|
||||
} else if (IS_VAR_DATA_TYPE(pTagVal->type)) {
|
||||
buf = taosMemoryCalloc(pTagVal->nData + 3, 1);
|
||||
bufSize = pTagVal->nData * 2 + 2 + 3;
|
||||
} else {
|
||||
buf = taosMemoryCalloc(32, 1);
|
||||
bufSize = pTagVal->nData + 3;
|
||||
}
|
||||
buf = taosMemoryCalloc(bufSize, 1);
|
||||
|
||||
RAW_NULL_CHECK(buf);
|
||||
if (!buf) goto end;
|
||||
if (dataConverToStr(buf, pTagVal->type, pTagVal->pData, pTagVal->nData, NULL) != TSDB_CODE_SUCCESS) {
|
||||
if (dataConverToStr(buf, bufSize, pTagVal->type, pTagVal->pData, pTagVal->nData, NULL) != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFree(buf);
|
||||
goto end;
|
||||
}
|
||||
|
@ -738,13 +738,15 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
|
|||
goto end;
|
||||
}
|
||||
} else {
|
||||
int64_t bufSize = 0;
|
||||
if (vAlterTbReq.tagType == TSDB_DATA_TYPE_VARBINARY) {
|
||||
buf = taosMemoryCalloc(vAlterTbReq.nTagVal * 2 + 2 + 3, 1);
|
||||
bufSize = vAlterTbReq.nTagVal * 2 + 2 + 3;
|
||||
} else {
|
||||
buf = taosMemoryCalloc(vAlterTbReq.nTagVal + 3, 1);
|
||||
bufSize = vAlterTbReq.nTagVal + 3;
|
||||
}
|
||||
buf = taosMemoryCalloc(bufSize, 1);
|
||||
RAW_NULL_CHECK(buf);
|
||||
if (dataConverToStr(buf, vAlterTbReq.tagType, vAlterTbReq.pTagVal, vAlterTbReq.nTagVal, NULL) !=
|
||||
if (dataConverToStr(buf, bufSize, vAlterTbReq.tagType, vAlterTbReq.pTagVal, vAlterTbReq.nTagVal, NULL) !=
|
||||
TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFree(buf);
|
||||
goto end;
|
||||
|
|
|
@ -2366,7 +2366,7 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
|
|||
TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)strictVstr, false), &lino, _OVER);
|
||||
|
||||
char durationVstr[128] = {0};
|
||||
int32_t len = formatDurationOrKeep(&durationVstr[VARSTR_HEADER_SIZE], pDb->cfg.daysPerFile);
|
||||
int32_t len = formatDurationOrKeep(&durationVstr[VARSTR_HEADER_SIZE], sizeof(durationVstr) - VARSTR_HEADER_SIZE, pDb->cfg.daysPerFile);
|
||||
|
||||
varDataSetLen(durationVstr, len);
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
|
@ -2377,9 +2377,9 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
|
|||
char keep1Str[128] = {0};
|
||||
char keep2Str[128] = {0};
|
||||
|
||||
int32_t lenKeep0 = formatDurationOrKeep(keep0Str, pDb->cfg.daysToKeep0);
|
||||
int32_t lenKeep1 = formatDurationOrKeep(keep1Str, pDb->cfg.daysToKeep1);
|
||||
int32_t lenKeep2 = formatDurationOrKeep(keep2Str, pDb->cfg.daysToKeep2);
|
||||
int32_t lenKeep0 = formatDurationOrKeep(keep0Str, sizeof(keep0Str), pDb->cfg.daysToKeep0);
|
||||
int32_t lenKeep1 = formatDurationOrKeep(keep1Str, sizeof(keep1Str), pDb->cfg.daysToKeep1);
|
||||
int32_t lenKeep2 = formatDurationOrKeep(keep2Str, sizeof(keep2Str), pDb->cfg.daysToKeep2);
|
||||
|
||||
if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) {
|
||||
len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%s,%s,%s", keep1Str, keep2Str, keep0Str);
|
||||
|
|
|
@ -345,20 +345,19 @@ static const char* encryptAlgorithmStr(int8_t encryptAlgorithm) {
|
|||
return TSDB_CACHE_MODEL_NONE_STR;
|
||||
}
|
||||
|
||||
int32_t formatDurationOrKeep(char* buffer, int32_t timeInMinutes) {
|
||||
if (buffer == NULL) {
|
||||
int32_t formatDurationOrKeep(char* buffer, int64_t bufSize, int32_t timeInMinutes) {
|
||||
if (buffer == NULL || bufSize <= 0) {
|
||||
return 0;
|
||||
}
|
||||
int lMaxLen = 32;
|
||||
int32_t len = 0;
|
||||
if (timeInMinutes % 1440 == 0) {
|
||||
int32_t days = timeInMinutes / 1440;
|
||||
len = snprintf(buffer, lMaxLen,"%dd", days);
|
||||
int32_t days = timeInMinutes / 1440;
|
||||
len = snprintf(buffer, bufSize, "%dd", days);
|
||||
} else if (timeInMinutes % 60 == 0) {
|
||||
int32_t hours = timeInMinutes / 60;
|
||||
len = snprintf(buffer, lMaxLen,"%dh", hours);
|
||||
int32_t hours = timeInMinutes / 60;
|
||||
len = snprintf(buffer, bufSize, "%dh", hours);
|
||||
} else {
|
||||
len = snprintf(buffer, lMaxLen,"%dm", timeInMinutes);
|
||||
len = snprintf(buffer, bufSize, "%dm", timeInMinutes);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
@ -405,10 +404,10 @@ static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName,
|
|||
char keep1Str[128] = {0};
|
||||
char keep2Str[128] = {0};
|
||||
|
||||
int32_t lenDuration = formatDurationOrKeep(durationStr, pCfg->daysPerFile);
|
||||
int32_t lenKeep0 = formatDurationOrKeep(keep0Str, pCfg->daysToKeep0);
|
||||
int32_t lenKeep1 = formatDurationOrKeep(keep1Str, pCfg->daysToKeep1);
|
||||
int32_t lenKeep2 = formatDurationOrKeep(keep2Str, pCfg->daysToKeep2);
|
||||
int32_t lenDuration = formatDurationOrKeep(durationStr, sizeof(durationStr), pCfg->daysPerFile);
|
||||
int32_t lenKeep0 = formatDurationOrKeep(keep0Str, sizeof(keep0Str), pCfg->daysToKeep0);
|
||||
int32_t lenKeep1 = formatDurationOrKeep(keep1Str, sizeof(keep1Str), pCfg->daysToKeep1);
|
||||
int32_t lenKeep2 = formatDurationOrKeep(keep2Str, sizeof(keep2Str), pCfg->daysToKeep2);
|
||||
|
||||
if (IS_SYS_DBNAME(dbName)) {
|
||||
len += snprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_DB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE, "CREATE DATABASE `%s`", dbName);
|
||||
|
@ -542,16 +541,16 @@ void appendTagFields(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
|
||||
SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
|
||||
char type[32];
|
||||
snprintf(type, 32, "%s", tDataTypes[pSchema->type].name);
|
||||
snprintf(type, sizeof(type), "%s", tDataTypes[pSchema->type].name);
|
||||
if (TSDB_DATA_TYPE_VARCHAR == pSchema->type || TSDB_DATA_TYPE_VARBINARY == pSchema->type ||
|
||||
TSDB_DATA_TYPE_GEOMETRY == pSchema->type) {
|
||||
snprintf(type + strlen(type), 32 - strlen(type), "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
|
||||
snprintf(type + strlen(type), sizeof(type) - strlen(type), "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
|
||||
} else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
|
||||
snprintf(type + strlen(type), 32 - strlen(type), "(%d)",
|
||||
snprintf(type + strlen(type), sizeof(type) - strlen(type), "(%d)",
|
||||
(int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
|
||||
}
|
||||
|
||||
*len += snprintf(buf + VARSTR_HEADER_SIZE + *len, 32 - (VARSTR_HEADER_SIZE + *len), "%s`%s` %s",
|
||||
*len += snprintf(buf + VARSTR_HEADER_SIZE + *len, sizeof(type) - (VARSTR_HEADER_SIZE + *len), "%s`%s` %s",
|
||||
((i > 0) ? ", " : ""), pSchema->name, type);
|
||||
}
|
||||
}
|
||||
|
@ -614,11 +613,17 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
|
|||
char type = pTagVal->type;
|
||||
int32_t tlen = 0;
|
||||
|
||||
int64_t leftSize = SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len);
|
||||
if (leftSize <= 0) {
|
||||
qError("no enough space to store tag value, leftSize:%" PRId64, leftSize);
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
TAOS_CHECK_ERRNO(code);
|
||||
}
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, pTagVal->pData, pTagVal->nData, &tlen);
|
||||
code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, leftSize, type, pTagVal->pData, pTagVal->nData, &tlen);
|
||||
TAOS_CHECK_ERRNO(code);
|
||||
} else {
|
||||
code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, type, &pTagVal->i64, tDataTypes[type].bytes, &tlen);
|
||||
code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, leftSize, type, &pTagVal->i64, tDataTypes[type].bytes, &tlen);
|
||||
TAOS_CHECK_ERRNO(code);
|
||||
}
|
||||
*len += tlen;
|
||||
|
|
|
@ -161,7 +161,7 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) {
|
|||
int len = strlen("TAOS_FQDN=") + strlen(taosFqdn) + 1;
|
||||
taosFqdnEnvItem = taosMemoryMalloc(len);
|
||||
if (taosFqdnEnvItem != NULL) {
|
||||
TAOS_STRNCPY(taosFqdnEnvItem, "TAOS_FQDN=", len);
|
||||
tstrncpy(taosFqdnEnvItem, "TAOS_FQDN=", len);
|
||||
TAOS_STRNCAT(taosFqdnEnvItem, taosFqdn, strlen(taosFqdn));
|
||||
fnInfo("[UDFD]Succsess to set TAOS_FQDN:%s", taosFqdn);
|
||||
} else {
|
||||
|
|
|
@ -313,42 +313,41 @@ void destroyQueryExecRes(SExecResult* pRes) {
|
|||
}
|
||||
}
|
||||
// clang-format on
|
||||
#define MAX_NUMERICAL_LENGTH (32)
|
||||
int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t* len) {
|
||||
int32_t dataConverToStr(char* str, int64_t capacity, int type, void* buf, int32_t bufSize, int32_t* len) {
|
||||
int32_t n = 0;
|
||||
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
n = snprintf(str, MAX_NUMERICAL_LENGTH, "null");
|
||||
n = snprintf(str, capacity, "null");
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
n = snprintf(str, MAX_NUMERICAL_LENGTH, (*(int8_t*)buf) ? "true" : "false");
|
||||
n = snprintf(str, capacity, (*(int8_t*)buf) ? "true" : "false");
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
n = snprintf(str, MAX_NUMERICAL_LENGTH, "%d", *(int8_t*)buf);
|
||||
n = snprintf(str, capacity, "%d", *(int8_t*)buf);
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
n = snprintf(str, MAX_NUMERICAL_LENGTH, "%d", *(int16_t*)buf);
|
||||
n = snprintf(str, capacity, "%d", *(int16_t*)buf);
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
n = snprintf(str, MAX_NUMERICAL_LENGTH, "%d", *(int32_t*)buf);
|
||||
n = snprintf(str, capacity, "%d", *(int32_t*)buf);
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
n = snprintf(str, MAX_NUMERICAL_LENGTH, "%" PRId64, *(int64_t*)buf);
|
||||
n = snprintf(str, capacity, "%" PRId64, *(int64_t*)buf);
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
n = snprintf(str, MAX_NUMERICAL_LENGTH, "%e", GET_FLOAT_VAL(buf));
|
||||
n = snprintf(str, capacity, "%e", GET_FLOAT_VAL(buf));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
n = snprintf(str, MAX_NUMERICAL_LENGTH, "%e", GET_DOUBLE_VAL(buf));
|
||||
n = snprintf(str, capacity, "%e", GET_DOUBLE_VAL(buf));
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_VARBINARY: {
|
||||
|
@ -395,19 +394,19 @@ int32_t dataConverToStr(char* str, int type, void* buf, int32_t bufSize, int32_t
|
|||
n = length + 2;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
n = snprintf(str, MAX_NUMERICAL_LENGTH, "%d", *(uint8_t*)buf);
|
||||
n = snprintf(str, capacity, "%d", *(uint8_t*)buf);
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
n = snprintf(str, MAX_NUMERICAL_LENGTH, "%d", *(uint16_t*)buf);
|
||||
n = snprintf(str, capacity, "%d", *(uint16_t*)buf);
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
n = snprintf(str, MAX_NUMERICAL_LENGTH, "%u", *(uint32_t*)buf);
|
||||
n = snprintf(str, capacity, "%u", *(uint32_t*)buf);
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
n = snprintf(str, MAX_NUMERICAL_LENGTH, "%" PRIu64, *(uint64_t*)buf);
|
||||
n = snprintf(str, capacity, "%" PRIu64, *(uint64_t*)buf);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in New Issue