From 3368e49039c65b03d1b4846bb019819be5c45f3b Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Fri, 22 Jan 2021 16:23:23 +0800 Subject: [PATCH] add assert --- src/client/src/tscSQLParser.c | 8 ++++++-- src/common/src/tname.c | 11 ++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 9745597d99..38d32cc025 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -902,13 +902,17 @@ int32_t parseSlidingClause(SSqlObj* pSql, SQueryInfo* pQueryInfo, SQuerySQL* pQu int32_t tscSetTableFullName(STableMetaInfo* pTableMetaInfo, SStrToken* pTableName, SSqlObj* pSql) { const char* msg1 = "name too long"; + const char* msg2 = "acctId too long"; SSqlCmd* pCmd = &pSql->cmd; int32_t code = TSDB_CODE_SUCCESS; if (hasSpecifyDB(pTableName)) { // db has been specified in sql string so we ignore current db path - tNameSetAcctId(&pTableMetaInfo->name, getAccountId(pSql)); - + code = tNameSetAcctId(&pTableMetaInfo->name, getAccountId(pSql)); + if (code != 0) { + return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2); + } + char name[TSDB_TABLE_FNAME_LEN] = {0}; strncpy(name, pTableName->z, pTableName->n); diff --git a/src/common/src/tname.c b/src/common/src/tname.c index 5c49e2e102..bbb0a8c082 100644 --- a/src/common/src/tname.c +++ b/src/common/src/tname.c @@ -367,6 +367,9 @@ int32_t tNameSetAcctId(SName* dst, const char* acct) { } tstrncpy(dst->acctId, acct, tListLen(dst->acctId)); + + assert(strlen(dst->acctId) > 0); + return 0; } @@ -383,12 +386,14 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) { int32_t len = (int32_t)(p - str); // too long account id or too long db name - if (len >= tListLen(dst->acctId) || len == 0) { + if ((len >= tListLen(dst->acctId)) || (len <= 0)) { return -1; } memcpy (dst->acctId, str, len); dst->acctId[len] = 0; + + assert(strlen(dst->acctId) > 0); } if ((type & T_NAME_DB) == T_NAME_DB) { @@ -404,7 +409,7 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) { } // too long account id or too long db name - if (len >= tListLen(dst->dbname) || len == 0) { + if ((len >= tListLen(dst->dbname)) || (len <= 0)) { return -1; } @@ -419,7 +424,7 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) { int32_t len = (int32_t) strlen(start); // too long account id or too long db name - if (len >= tListLen(dst->tname) || len == 0) { + if ((len >= tListLen(dst->tname)) || (len <= 0)) { return -1; }