提交 89aa04de 编写于 作者: H Hui Li

[modify for coverity scan]

上级 ea0c4dee
......@@ -116,6 +116,8 @@ extern "C" {
#define POW2(x) ((x) * (x))
int taosRand(void);
int32_t strdequote(char *src);
size_t strtrim(char *src);
......
......@@ -506,7 +506,7 @@ void taosAddToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
void taosRemoveFromTrashCan(SCacheObj *pCacheObj, STrashElem *pElem) {
if (pElem->pData->signature != (uint64_t)pElem->pData) {
uError("key:sig:0x%x %p data has been released, ignore", pElem->pData->signature, pElem->pData);
uError("key:sig:0x%" PRIx64 " %p data has been released, ignore", pElem->pData->signature, pElem->pData);
return;
}
......
......@@ -119,9 +119,14 @@ static void taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
struct stat dirstat;
if (stat(option, &dirstat) < 0) {
int code = mkdir(option, 0755);
if (code < 0) {
uError("config option:%s, input value:%s, directory not exist, create fail with return code:%d",
cfg->option, input_value, code);
} else {
uPrint("config option:%s, input value:%s, directory not exist, create with return code:%d",
cfg->option, input_value, code);
}
}
cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
} else {
uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value,
......
......@@ -140,7 +140,7 @@ void print_char_as_binary(char input) {
void generate_key(unsigned char* key) {
int i;
for (i = 0; i < 8; i++) {
key[i] = rand() % 255;
key[i] = taosRand() % 255;
}
}
......
......@@ -233,7 +233,9 @@ static void taosGetLogFileName(char *fn) {
}
}
if (strlen(fn) < LOG_FILE_NAME_LEN) {
strcpy(tsLogObj.logName, fn);
}
}
static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
......@@ -253,15 +255,20 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
tsLogObj.fileNum = maxFileNum;
taosGetLogFileName(fn);
if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) {
strcpy(name, fn);
strcat(name, ".0");
}
// if none of the log files exist, open 0, if both exists, open the old one
if (stat(name, &logstat0) < 0) {
tsLogObj.flag = 0;
} else {
if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) {
strcpy(name, fn);
strcat(name, ".1");
}
if (stat(name, &logstat1) < 0) {
tsLogObj.flag = 1;
} else {
......
......@@ -169,7 +169,9 @@ void taosGetNoteName(char *fn, taosNoteInfo * pNote)
}
}
if (strlen(fn) < NOTE_FILE_NAME_LEN) {
strcpy(pNote->taosNoteName, fn);
}
}
int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum, taosNoteInfo * pNote)
......@@ -182,14 +184,18 @@ int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum, taosNoteInf
pNote->taosNoteFileNum = maxNoteNum;
taosGetNoteName(fn, pNote);
if (strlen(fn) > NOTE_FILE_NAME_LEN * 2 - 2) {
fprintf(stderr, "the len of file name overflow:%s\n", fn);
return -1;
}
strcpy(name, fn);
strcat(name, ".0");
// if none of the note files exist, open 0, if both exists, open the old one
if (stat(name, &notestat0) < 0) {
pNote->taosNoteFlag = 0;
}
else {
} else {
strcpy(name, fn);
strcat(name, ".1");
if (stat(name, &notestat1) < 0) {
......
......@@ -38,7 +38,7 @@ static FORCE_INLINE int32_t getSkipListNodeRandomHeight(SSkipList *pSkipList) {
const uint32_t factor = 4;
int32_t n = 1;
while ((rand() % factor) == 0 && n <= pSkipList->maxLevel) {
while ((taosRand() % factor) == 0 && n <= pSkipList->maxLevel) {
n++;
}
......
......@@ -27,6 +27,27 @@
#include "tulog.h"
#include "taoserror.h"
#ifdef WINDOWS
int taosRand(void)
{
return rand();
}
#else
int taosRand(void)
{
int fd;
unsigned long seed;
fd = open("/dev/urandom", 0);
if ((fd < 0) || (read(fd, &seed, sizeof(seed)) < 0)) seed = time(0);
if (fd >= 0) close(fd);
srand(seed);
return rand();
}
#endif
int32_t strdequote(char *z) {
if (z == NULL) {
return 0;
......@@ -434,8 +455,10 @@ void getTmpfilePath(const char *fileNamePrefix, char *dstPath) {
strcpy(tmpPath, tmpDir);
strcat(tmpPath, tdengineTmpFileNamePrefix);
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
strcat(tmpPath, fileNamePrefix);
strcat(tmpPath, "-%d-%s");
}
char rand[8] = {0};
taosRandStr(rand, tListLen(rand) - 1);
......@@ -447,7 +470,7 @@ void taosRandStr(char* str, int32_t size) {
int32_t len = 39;
for(int32_t i = 0; i < size; ++i) {
str[i] = set[rand()%len];
str[i] = set[taosRand()%len];
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册