fix tests

This commit is contained in:
wangjiaming0909 2024-12-03 08:56:53 +08:00
parent 9a01b42bc2
commit 2bf3da7415
5 changed files with 48 additions and 45 deletions

View File

@ -50,12 +50,12 @@
} \
} while (0)
#define COPY_STRING_FORM_ID_TOKEN(buf, pToken) tstrncpy(buf, (pToken)->z, TMIN((pToken)->n + 1, sizeof(buf)))
#define COPY_STRING_FORM_STR_TOKEN(buf, pToken) \
do { \
if ((pToken)->n > 2) { \
tstrncpy(buf, (pToken)->z + 1, TMIN((pToken)->n - 1, sizeof(buf))); \
} \
#define COPY_STRING_FORM_ID_TOKEN(buf, pToken) strncpy(buf, (pToken)->z, TMIN((pToken)->n, sizeof(buf) - 1))
#define COPY_STRING_FORM_STR_TOKEN(buf, pToken) \
do { \
if ((pToken)->n > 2) { \
strncpy(buf, (pToken)->z + 1, TMIN((pToken)->n - 2, sizeof(buf) - 1)); \
} \
} while (0)
SToken nil_token = {.type = TK_NK_NIL, .n = 0, .z = NULL};
@ -113,7 +113,7 @@ static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken,
} else if (pPasswordToken->n >= (TSDB_USET_PASSWORD_LEN + 2)) {
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
} else {
tstrncpy(pPassword, pPasswordToken->z, TMIN(TSDB_USET_PASSWORD_LEN, pPasswordToken->n + 1));
strncpy(pPassword, pPasswordToken->z, pPasswordToken->n);
(void)strdequote(pPassword);
if (strtrim(pPassword) <= 0) {
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_PASSWD_EMPTY);
@ -151,7 +151,7 @@ static int32_t parseEndpoint(SAstCreateContext* pCxt, const SToken* pEp, char* p
tstrncpy(pFqdn, ep, TSDB_FQDN_LEN);
return TSDB_CODE_SUCCESS;
}
tstrncpy(pFqdn, ep, pColon - ep + 1);
strncpy(pFqdn, ep, pColon - ep);
return parsePort(pCxt, pColon + 1, pPort);
}
@ -327,14 +327,15 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
tstrncpy(pExpr->userAlias, ((SFunctionNode*)pExpr)->functionName, TSDB_COL_NAME_LEN);
tstrncpy(pExpr->aliasName, ((SFunctionNode*)pExpr)->functionName, TSDB_COL_NAME_LEN);
} else {
int32_t len = TMIN(sizeof(pExpr->aliasName), pRawExpr->n + 1);
int32_t len = TMIN(sizeof(pExpr->aliasName) - 1, pRawExpr->n);
// See TS-3398.
// Len of pRawExpr->p could be larger than len of aliasName[TSDB_COL_NAME_LEN].
// If aliasName is truncated, hash value of aliasName could be the same.
uint64_t hashVal = MurmurHash3_64(pRawExpr->p, pRawExpr->n);
snprintf(pExpr->aliasName, TSDB_COL_NAME_LEN, "%" PRIu64, hashVal);
tstrncpy(pExpr->userAlias, pRawExpr->p, len);
strncpy(pExpr->userAlias, pRawExpr->p, len);
pExpr->userAlias[len] = 0;
}
}
pRawExpr->pNode = NULL;
@ -1022,7 +1023,7 @@ static SNode* createPrimaryKeyCol(SAstCreateContext* pCxt, const SToken* pFuncNa
if (NULL == pFuncName) {
tstrncpy(pCol->colName, ROWTS_PSEUDO_COLUMN_NAME, TSDB_COL_NAME_LEN);
} else {
tstrncpy(pCol->colName, pFuncName->z, pFuncName->n + 1);
strncpy(pCol->colName, pFuncName->z, pFuncName->n);
}
pCol->isPrimTs = true;
return (SNode*)pCol;
@ -1524,9 +1525,11 @@ SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, SToken* pAlias)
CHECK_PARSER_STATUS(pCxt);
trimEscape(pAlias);
SExprNode* pExpr = (SExprNode*)pNode;
int32_t len = TMIN(sizeof(pExpr->aliasName), pAlias->n + 1);
tstrncpy(pExpr->aliasName, pAlias->z, len);
tstrncpy(pExpr->userAlias, pAlias->z, len);
int32_t len = TMIN(sizeof(pExpr->aliasName) - 1, pAlias->n);
strncpy(pExpr->aliasName, pAlias->z, len);
pExpr->aliasName[len] = '\0';
strncpy(pExpr->userAlias, pAlias->z, len);
pExpr->userAlias[len] = '\0';
pExpr->asAlias = true;
return pNode;
_err:
@ -2242,7 +2245,7 @@ SNode* setColumnOptions(SAstCreateContext* pCxt, SNode* pOptions, const SToken*
char optionType[TSDB_CL_OPTION_LEN];
memset(optionType, 0, TSDB_CL_OPTION_LEN);
tstrncpy(optionType, pVal1->z, TMIN(pVal1->n, TSDB_CL_OPTION_LEN));
strncpy(optionType, pVal1->z, TMIN(pVal1->n, TSDB_CL_OPTION_LEN));
if (0 == strlen(optionType)) {
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
return pOptions;
@ -2374,7 +2377,7 @@ SNode* createCreateSubTableFromFileClause(SAstCreateContext* pCxt, bool ignoreEx
if (TK_NK_STRING == pFilePath->type) {
(void)trimString(pFilePath->z, pFilePath->n, pStmt->filePath, PATH_MAX);
} else {
tstrncpy(pStmt->filePath, pFilePath->z, TMIN(PATH_MAX, pFilePath->n + 1));
strncpy(pStmt->filePath, pFilePath->z, pFilePath->n);
}
nodesDestroyNode(pUseRealTable);

View File

@ -2131,7 +2131,7 @@ static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal,
return generateDealNodeErrMsg(pCxt, terrno);
}
varDataSetLen(pVal->datum.p, len);
tstrncpy(varDataVal(pVal->datum.p), pVal->literal, len);
strncpy(varDataVal(pVal->datum.p), pVal->literal, len);
break;
}
case TSDB_DATA_TYPE_TIMESTAMP: {
@ -4395,7 +4395,7 @@ static EDealRes doTranslateTbName(SNode** pNode, void* pContext) {
return DEAL_RES_ERROR;
}
varDataSetLen(pVal->datum.p, tbLen);
tstrncpy(varDataVal(pVal->datum.p), pVal->literal, tbLen);
tstrncpy(varDataVal(pVal->datum.p), pVal->literal, tbLen + 1);
tstrncpy(pVal->node.userAlias, pFunc->node.userAlias, TSDB_COL_NAME_LEN);
tstrncpy(pVal->node.aliasName, pFunc->node.aliasName, TSDB_COL_NAME_LEN);
nodesDestroyNode(*pNode);

View File

@ -606,7 +606,7 @@ static int32_t getIntegerFromAuthStr(const char* pStart, char** pNext) {
tstrncpy(buf, pStart, 10);
*pNext = NULL;
} else {
tstrncpy(buf, pStart, p - pStart + 1);
strncpy(buf, pStart, p - pStart);
*pNext = ++p;
}
return taosStr2Int32(buf, NULL, 10);
@ -618,7 +618,7 @@ static void getStringFromAuthStr(const char* pStart, char* pStr, char** pNext) {
tstrncpy(pStr, pStart, strlen(pStart) + 1);
*pNext = NULL;
} else {
tstrncpy(pStr, pStart, p - pStart + 1);
strncpy(pStr, pStart, p - pStart);
*pNext = ++p;
}
if (*pStart == '`' && *(pStart + 1) == '`') {
@ -652,7 +652,7 @@ static int32_t buildTableReq(SHashObj* pTablesHash, SArray** pTables) {
size_t len = 0;
char* pKey = taosHashGetKey(p, &len);
char fullName[TSDB_TABLE_FNAME_LEN] = {0};
tstrncpy(fullName, pKey, len);
strncpy(fullName, pKey, len);
SName name = {0};
int32_t code = tNameFromString(&name, fullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
if (TSDB_CODE_SUCCESS == code) {
@ -683,7 +683,7 @@ static int32_t buildDbReq(SHashObj* pDbsHash, SArray** pDbs) {
size_t len = 0;
char* pKey = taosHashGetKey(p, &len);
char fullName[TSDB_DB_FNAME_LEN] = {0};
tstrncpy(fullName, pKey, len);
strncpy(fullName, pKey, len);
if (NULL == taosArrayPush(*pDbs, fullName)) {
taosHashCancelIterate(pDbsHash, p);
taosArrayDestroy(*pDbs);
@ -737,7 +737,7 @@ static int32_t buildUserAuthReq(SHashObj* pUserAuthHash, SArray** pUserAuth) {
size_t len = 0;
char* pKey = taosHashGetKey(p, &len);
char key[USER_AUTH_KEY_MAX_LEN] = {0};
tstrncpy(key, pKey, len);
strncpy(key, pKey, len);
SUserAuthInfo userAuth = {0};
stringToUserAuth(key, len, &userAuth);
if (NULL == taosArrayPush(*pUserAuth, &userAuth)) {
@ -763,7 +763,7 @@ static int32_t buildUdfReq(SHashObj* pUdfHash, SArray** pUdf) {
size_t len = 0;
char* pFunc = taosHashGetKey(p, &len);
char func[TSDB_FUNC_NAME_LEN] = {0};
tstrncpy(func, pFunc, len);
strncpy(func, pFunc, len);
if (NULL == taosArrayPush(*pUdf, func)) {
taosHashCancelIterate(pUdfHash, p);
taosArrayDestroy(*pUdf);

View File

@ -109,7 +109,7 @@ bool qParseDbName(const char* pStr, size_t length, char** pDbName) {
if (*pDbName == NULL) {
return false;
}
tstrncpy(*pDbName, t.z, dbNameLen);
strncpy(*pDbName, t.z, dbNameLen);
(*pDbName)[dbNameLen] = '\0';
return true;
}
@ -185,7 +185,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_MULTI_BIND* pParam) {
return terrno;
}
varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
tstrncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes);
strncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes);
pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
break;
case TSDB_DATA_TYPE_NCHAR: {
@ -472,7 +472,7 @@ static int32_t setValueByBindParam2(SValueNode* pVal, TAOS_STMT2_BIND* pParam) {
return terrno;
}
varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
tstrncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes);
strncpy(varDataVal(pVal->datum.p), (const char*)pParam->buffer, pVal->node.resType.bytes);
pVal->node.resType.bytes += VARSTR_HEADER_SIZE;
break;
case TSDB_DATA_TYPE_NCHAR: {

View File

@ -41,9 +41,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strncat(*ppKey, pStmtName, TSDB_TABLE_NAME_LEN);
strncat(*ppKey, ".", 2);
strncat(*ppKey, pCol->node.aliasName, TSDB_COL_NAME_LEN);
TAOS_STRNCAT(*ppKey, pStmtName, TSDB_TABLE_NAME_LEN);
TAOS_STRNCAT(*ppKey, ".", 2);
TAOS_STRNCAT(*ppKey, pCol->node.aliasName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code;
} else {
@ -51,7 +51,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strncat(*ppKey, pCol->node.aliasName, TSDB_COL_NAME_LEN);
TAOS_STRNCAT(*ppKey, pCol->node.aliasName, TSDB_COL_NAME_LEN);
*pLen = strlen(*ppKey);
return code;
}
@ -61,7 +61,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strncat(*ppKey, pCol->colName, TSDB_COL_NAME_LEN);
TAOS_STRNCAT(*ppKey, pCol->colName, TSDB_COL_NAME_LEN);
*pLen = strlen(*ppKey);
return code;
}
@ -70,9 +70,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strncat(*ppKey, pCol->tableAlias, TSDB_TABLE_NAME_LEN);
strncat(*ppKey, ".", 2);
strncat(*ppKey, pCol->colName, TSDB_COL_NAME_LEN);
TAOS_STRNCAT(*ppKey, pCol->tableAlias, TSDB_TABLE_NAME_LEN);
TAOS_STRNCAT(*ppKey, ".", 2);
TAOS_STRNCAT(*ppKey, pCol->colName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code;
} else if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
@ -85,9 +85,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strncat(*ppKey, pStmtName, TSDB_TABLE_NAME_LEN);
strncat(*ppKey, ".", 2);
strncat(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
TAOS_STRNCAT(*ppKey, pStmtName, TSDB_TABLE_NAME_LEN);
TAOS_STRNCAT(*ppKey, ".", 2);
TAOS_STRNCAT(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code;
}
@ -95,9 +95,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strncat(*ppKey, pVal->literal, strlen(pVal->literal));
strncat(*ppKey, ".", 2);
strncat(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
TAOS_STRNCAT(*ppKey, pVal->literal, strlen(pVal->literal));
TAOS_STRNCAT(*ppKey, ".", 2);
TAOS_STRNCAT(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code;
}
@ -109,9 +109,9 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strncat(*ppKey, pStmtName, TSDB_TABLE_NAME_LEN);
strncat(*ppKey, ".", 2);
strncat(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
TAOS_STRNCAT(*ppKey, pStmtName, TSDB_TABLE_NAME_LEN);
TAOS_STRNCAT(*ppKey, ".", 2);
TAOS_STRNCAT(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
*pLen = taosHashBinary(*ppKey, strlen(*ppKey));
return code;
}
@ -120,7 +120,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
if (!*ppKey) {
return terrno;
}
strncat(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
TAOS_STRNCAT(*ppKey, ((SExprNode*)pNode)->aliasName, TSDB_COL_NAME_LEN);
*pLen = strlen(*ppKey);
return code;
}