未验证 提交 2ba8fef0 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #17571 from taosdata/fix/TD-19655-V30

fix(all): fixed coverity scan problems for second submiting
...@@ -191,7 +191,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) { ...@@ -191,7 +191,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
printf("failed to rename file %s to %s, reason:%s\n", oldName, newName, strerror(errno)); printf("failed to rename file %s to %s, reason:%s\n", oldName, newName, strerror(errno));
} }
return !code; return code ? 0 : -1;
#else #else
int32_t code = rename(oldName, newName); int32_t code = rename(oldName, newName);
if (code < 0) { if (code < 0) {
......
...@@ -2274,6 +2274,9 @@ int32_t tsCompressBool(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t ...@@ -2274,6 +2274,9 @@ int32_t tsCompressBool(void *pIn, int32_t nIn, int32_t nEle, void *pOut, int32_t
return tsCompressBoolImp(pIn, nEle, pOut); return tsCompressBoolImp(pIn, nEle, pOut);
} else if (cmprAlg == TWO_STAGE_COMP) { } else if (cmprAlg == TWO_STAGE_COMP) {
int32_t len = tsCompressBoolImp(pIn, nEle, pBuf); int32_t len = tsCompressBoolImp(pIn, nEle, pBuf);
if (len < 0) {
return -1;
}
return tsCompressStringImp(pBuf, len, pOut, nOut); return tsCompressStringImp(pBuf, len, pOut, nOut);
} else { } else {
assert(0); assert(0);
......
...@@ -263,7 +263,7 @@ double tdigestQuantile(TDigest *t, double q) { ...@@ -263,7 +263,7 @@ double tdigestQuantile(TDigest *t, double q) {
b = c; b = c;
right = (b->weight * a->mean + a->weight * b->mean) / (a->weight + b->weight); right = (b->weight * a->mean + a->weight * b->mean) / (a->weight + b->weight);
if (idx < weight_so_far + a->weight) { if (idx < weight_so_far + a->weight) {
double p = (idx - weight_so_far) / a->weight; double p = (idx - weight_so_far) / ((a->weight == 0) ? 1 : a->weight);
return left * (1 - p) + right * p; return left * (1 - p) + right * p;
} }
weight_so_far += a->weight; weight_so_far += a->weight;
......
...@@ -109,7 +109,7 @@ void tEndEncode(SEncoder* pCoder) { ...@@ -109,7 +109,7 @@ void tEndEncode(SEncoder* pCoder) {
pCoder->size = pNode->size; pCoder->size = pNode->size;
pCoder->pos = pNode->pos; pCoder->pos = pNode->pos;
tEncodeI32(pCoder, len); (void)tEncodeI32(pCoder, len);
TD_CODER_MOVE_POS(pCoder, len); TD_CODER_MOVE_POS(pCoder, len);
} }
......
...@@ -54,7 +54,7 @@ int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t c ...@@ -54,7 +54,7 @@ int32_t taosEnvNameToCfgName(const char *envNameStr, char *cfgNameStr, int32_t c
} }
int32_t taosEnvToCfg(const char *envStr, char *cfgStr) { int32_t taosEnvToCfg(const char *envStr, char *cfgStr) {
if (envStr == NULL && cfgStr == NULL) { if (envStr == NULL || cfgStr == NULL) {
return -1; return -1;
} }
if (cfgStr != envStr) strcpy(cfgStr, envStr); if (cfgStr != envStr) strcpy(cfgStr, envStr);
......
...@@ -639,7 +639,7 @@ void taosHashTableResize(SHashObj *pHashObj) { ...@@ -639,7 +639,7 @@ void taosHashTableResize(SHashObj *pHashObj) {
} }
int64_t st = taosGetTimestampUs(); int64_t st = taosGetTimestampUs();
void *pNewEntryList = taosMemoryRealloc(pHashObj->hashList, sizeof(void *) * newCapacity); SHashEntry **pNewEntryList = taosMemoryRealloc(pHashObj->hashList, sizeof(SHashEntry *) * newCapacity);
if (pNewEntryList == NULL) { if (pNewEntryList == NULL) {
// uDebug("cache resize failed due to out of memory, capacity remain:%zu", pHashObj->capacity); // uDebug("cache resize failed due to out of memory, capacity remain:%zu", pHashObj->capacity);
return; return;
......
...@@ -207,7 +207,8 @@ static void taosKeepOldLog(char *oldName) { ...@@ -207,7 +207,8 @@ static void taosKeepOldLog(char *oldName) {
char fileName[LOG_FILE_NAME_LEN + 20]; char fileName[LOG_FILE_NAME_LEN + 20];
snprintf(fileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64, tsLogObj.logName, fileSec); snprintf(fileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64, tsLogObj.logName, fileSec);
taosRenameFile(oldName, fileName); (void)taosRenameFile(oldName, fileName);
if (tsLogKeepDays < 0) { if (tsLogKeepDays < 0) {
char compressFileName[LOG_FILE_NAME_LEN + 20]; char compressFileName[LOG_FILE_NAME_LEN + 20];
snprintf(compressFileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64 ".gz", tsLogObj.logName, fileSec); snprintf(compressFileName, LOG_FILE_NAME_LEN + 20, "%s.%" PRId64 ".gz", tsLogObj.logName, fileSec);
......
...@@ -337,6 +337,7 @@ static int taosLRUCacheShardInit(SLRUCacheShard *shard, size_t capacity, bool st ...@@ -337,6 +337,7 @@ static int taosLRUCacheShardInit(SLRUCacheShard *shard, size_t capacity, bool st
taosThreadMutexInit(&shard->mutex, NULL); taosThreadMutexInit(&shard->mutex, NULL);
taosThreadMutexLock(&shard->mutex);
shard->capacity = 0; shard->capacity = 0;
shard->highPriPoolUsage = 0; shard->highPriPoolUsage = 0;
shard->strictCapacity = strict; shard->strictCapacity = strict;
...@@ -349,6 +350,7 @@ static int taosLRUCacheShardInit(SLRUCacheShard *shard, size_t capacity, bool st ...@@ -349,6 +350,7 @@ static int taosLRUCacheShardInit(SLRUCacheShard *shard, size_t capacity, bool st
shard->lru.next = &shard->lru; shard->lru.next = &shard->lru;
shard->lru.prev = &shard->lru; shard->lru.prev = &shard->lru;
shard->lruLowPri = &shard->lru; shard->lruLowPri = &shard->lru;
taosThreadMutexUnlock(&shard->mutex);
taosLRUCacheShardSetCapacity(shard, capacity); taosLRUCacheShardSetCapacity(shard, capacity);
......
...@@ -534,7 +534,9 @@ void destroyDiskbasedBuf(SDiskbasedBuf* pBuf) { ...@@ -534,7 +534,9 @@ void destroyDiskbasedBuf(SDiskbasedBuf* pBuf) {
} }
} }
taosRemoveFile(pBuf->path); if (taosRemoveFile(pBuf->path) < 0) {
uDebug("WARNING tPage remove file failed. path=%s", pBuf->path);
}
taosMemoryFreeClear(pBuf->path); taosMemoryFreeClear(pBuf->path);
size_t n = taosArrayGetSize(pBuf->pIdList); size_t n = taosArrayGetSize(pBuf->pIdList);
......
...@@ -78,7 +78,7 @@ bool insertWord(STire* tire, char* word); ...@@ -78,7 +78,7 @@ bool insertWord(STire* tire, char* word);
bool deleteWord(STire* tire, char* word); bool deleteWord(STire* tire, char* word);
// match prefix words, if match is not NULL , put all item to match and return match // match prefix words, if match is not NULL , put all item to match and return match
SMatch* matchPrefix(STire* tire, char* prefix, SMatch* match); void matchPrefix(STire* tire, char* prefix, SMatch* match);
// get all items from tires tree // get all items from tires tree
SMatch* enumAll(STire* tire); SMatch* enumAll(STire* tire);
......
...@@ -564,6 +564,7 @@ void parseCommand(SWords* command, bool pattern) { ...@@ -564,6 +564,7 @@ void parseCommand(SWords* command, bool pattern) {
// free SShellCmd // free SShellCmd
void freeCommand(SWords* command) { void freeCommand(SWords* command) {
SWord* item = command->head; SWord* item = command->head;
command->head = NULL;
// loop // loop
while (item) { while (item) {
SWord* tmp = item; SWord* tmp = item;
...@@ -815,7 +816,9 @@ char* matchNextPrefix(STire* tire, char* pre) { ...@@ -815,7 +816,9 @@ char* matchNextPrefix(STire* tire, char* pre) {
match = enumAll(tire); match = enumAll(tire);
} else { } else {
// NOT EMPTY // NOT EMPTY
match = matchPrefix(tire, pre, NULL); match = (SMatch*)taosMemoryMalloc(sizeof(SMatch));
memset(match, 0, sizeof(SMatch));
matchPrefix(tire, pre, match);
} }
// save to lastMatch // save to lastMatch
...@@ -828,7 +831,7 @@ char* matchNextPrefix(STire* tire, char* pre) { ...@@ -828,7 +831,7 @@ char* matchNextPrefix(STire* tire, char* pre) {
// check valid // check valid
if (match == NULL || match->head == NULL) { if (match == NULL || match->head == NULL) {
// no one matched // no one matched
return false; return NULL;
} }
if (cursorVar == -1) { if (cursorVar == -1) {
......
...@@ -308,25 +308,21 @@ void matchPrefixFromTree(STire* tire, char* prefix, SMatch* match) { ...@@ -308,25 +308,21 @@ void matchPrefixFromTree(STire* tire, char* prefix, SMatch* match) {
} }
} }
SMatch* matchPrefix(STire* tire, char* prefix, SMatch* match) { void matchPrefix(STire* tire, char* prefix, SMatch* match) {
SMatch* rMatch = match; // define return match if (match == NULL) {
if (rMatch == NULL) { return;
rMatch = (SMatch*)taosMemoryMalloc(sizeof(SMatch));
memset(rMatch, 0, sizeof(SMatch));
} }
switch (tire->type) { switch (tire->type) {
case TIRE_TREE: case TIRE_TREE:
matchPrefixFromTree(tire, prefix, rMatch); matchPrefixFromTree(tire, prefix, match);
break; break;
case TIRE_LIST: case TIRE_LIST:
matchPrefixFromList(tire, prefix, rMatch); matchPrefixFromList(tire, prefix, match);
break; break;
default: default:
break; break;
} }
return rMatch;
} }
// get all items from tires tree // get all items from tires tree
...@@ -360,10 +356,11 @@ void enumFromTree(STire* tire, SMatch* match) { ...@@ -360,10 +356,11 @@ void enumFromTree(STire* tire, SMatch* match) {
} }
// this branch have data // this branch have data
if (c->end) if (c->end) {
addWordToMatch(match, pre); addWordToMatch(match, pre);
else } else {
matchPrefix(tire, pre, match); matchPrefix(tire, pre, match);
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册