From e1370ae24d4ca5ee74eb942477335f3da47985fa Mon Sep 17 00:00:00 2001 From: Hui Li Date: Tue, 23 Jun 2020 15:06:02 +0800 Subject: [PATCH] [modify for coverity scan] --- src/kit/taosdump/taosdump.c | 29 +++++++++++++++++++---------- src/util/src/tconfig.c | 17 +++++++---------- src/util/src/tlog.c | 9 +++++---- src/util/src/ttime.c | 2 +- 4 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 678de7daa7..63cdf259d6 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -644,14 +644,15 @@ int taosDumpDb(SDbInfo *dbInfo, SDumpArguments *arguments, FILE *fp) { (void)lseek(fd, 0, SEEK_SET); + STableRecord tableInfo; while (1) { - memset(&tableRecord, 0, sizeof(STableRecord)); - ssize_t ret = read(fd, &tableRecord, sizeof(STableRecord)); + memset(&tableInfo, 0, sizeof(STableRecord)); + ssize_t ret = read(fd, &tableInfo, sizeof(STableRecord)); if (ret <= 0) break; - tableRecord.name[sizeof(tableRecord.name) - 1] = 0; - tableRecord.metric[sizeof(tableRecord.metric) - 1] = 0; - taosDumpTable(tableRecord.name, tableRecord.metric, arguments, fp); + tableInfo.name[sizeof(tableInfo.name) - 1] = 0; + tableInfo.metric[sizeof(tableInfo.metric) - 1] = 0; + taosDumpTable(tableInfo.name, tableInfo.metric, arguments, fp); } close(fd); @@ -910,14 +911,22 @@ int32_t taosDumpMetric(char *metric, SDumpArguments *arguments, FILE *fp) { (void)lseek(fd, 0, SEEK_SET); + STableRecord tableInfo; + char tableName[TSDB_TABLE_NAME_LEN] ; + char metricName[TSDB_TABLE_NAME_LEN]; while (1) { - memset(&tableRecord, 0, sizeof(STableRecord)); - ssize_t ret = read(fd, &tableRecord, sizeof(STableRecord)); + memset(&tableInfo, 0, sizeof(STableRecord)); + memset(tableName, 0, TSDB_TABLE_NAME_LEN); + memset(metricName, 0, TSDB_TABLE_NAME_LEN); + ssize_t ret = read(fd, &tableInfo, sizeof(STableRecord)); if (ret <= 0) break; - tableRecord.name[sizeof(tableRecord.name) - 1] = 0; - tableRecord.metric[sizeof(tableRecord.metric) - 1] = 0; - taosDumpTable(tableRecord.name, tableRecord.metric, arguments, fp); + //tableInfo.name[sizeof(tableInfo.name) - 1] = 0; + //tableInfo.metric[sizeof(tableInfo.metric) - 1] = 0; + //taosDumpTable(tableInfo.name, tableInfo.metric, arguments, fp); + tstrncpy(tableName, tableInfo.name, TSDB_TABLE_NAME_LEN-1); + tstrncpy(metricName, tableInfo.metric, TSDB_TABLE_NAME_LEN-1); + taosDumpTable(tableName, metricName, arguments, fp); } close(fd); diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index bcea8d1654..76772db4e0 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -111,21 +111,18 @@ static void taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { wordfree(&full_path); return; } + if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { strcpy(option, full_path.we_wordv[0]); } + wordfree(&full_path); - 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); - } + int code = tmkdir(option, 0755); + if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + uError("config option:%s, input value:%s, directory not exist, create fail:%s", + cfg->option, input_value, strerror(errno)); } cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE; } else { diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 50dae7b177..581c4e2e9f 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -276,14 +276,15 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { } } - sprintf(name, "%s.%d", tsLogObj.logName, tsLogObj.flag); + char fileName[LOG_FILE_NAME_LEN + 50] = "\0"; + sprintf(fileName, "%s.%d", tsLogObj.logName, tsLogObj.flag); pthread_mutex_init(&tsLogObj.logMutex, NULL); umask(0); - tsLogObj.logHandle->fd = open(name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); + tsLogObj.logHandle->fd = open(fileName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); if (tsLogObj.logHandle->fd < 0) { - printf("\nfailed to open log file:%s, reason:%s\n", name, strerror(errno)); + printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno)); return -1; } taosLockFile(tsLogObj.logHandle->fd); @@ -291,7 +292,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { // only an estimate for number of lines struct stat filestat; if (fstat(tsLogObj.logHandle->fd, &filestat) < 0) { - printf("\nfailed to fstat log file:%s, reason:%s\n", name, strerror(errno)); + printf("\nfailed to fstat log file:%s, reason:%s\n", fileName, strerror(errno)); return -1; } size = (int32_t)filestat.st_size; diff --git a/src/util/src/ttime.c b/src/util/src/ttime.c index 02d72dd1f4..5feda312b1 100644 --- a/src/util/src/ttime.c +++ b/src/util/src/ttime.c @@ -56,7 +56,7 @@ int64_t user_mktime64(const unsigned int year0, const unsigned int mon0, year -= 1; } - int64_t res = (((((int64_t) (year/4 - year/100 + year/400 + 367*mon/12 + day) + + int64_t res = (((((int64_t) (year/4 - year/100 + year/400 + (int64_t)(367*mon)/12 + day) + year*365 - 719499)*24 + hour)*60 + min)*60 + sec); return (res + timezone); -- GitLab