未验证 提交 1d9d7569 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

Merge pull request #5374 from taosdata/hotfix/sangshuduo/TD-3197-fix-taosdemo-coverity-scan

[TD-3197] <fix>: fix taosdump and taosdemo coverity scan issue.
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "cJSON.h" #include "cJSON.h"
#include "taos.h" #include "taos.h"
#include "taoserror.h"
#include "tutil.h" #include "tutil.h"
#define REQ_EXTRA_BUF_LEN 1024 #define REQ_EXTRA_BUF_LEN 1024
...@@ -838,7 +839,8 @@ static void getResult(TAOS_RES *res, char* resultFileName) { ...@@ -838,7 +839,8 @@ static void getResult(TAOS_RES *res, char* resultFileName) {
char* databuf = (char*) calloc(1, 100*1024*1024); char* databuf = (char*) calloc(1, 100*1024*1024);
if (databuf == NULL) { if (databuf == NULL) {
fprintf(stderr, "failed to malloc, warning: save result to file slowly!\n"); fprintf(stderr, "failed to malloc, warning: save result to file slowly!\n");
fclose(fp); if (fp)
fclose(fp);
return ; return ;
} }
...@@ -1669,6 +1671,7 @@ int postProceSql(char* host, uint16_t port, char* sqlstr) ...@@ -1669,6 +1671,7 @@ int postProceSql(char* host, uint16_t port, char* sqlstr)
ERROR_EXIT("ERROR storing complete response from socket"); ERROR_EXIT("ERROR storing complete response from socket");
} }
response_buf[RESP_BUF_LEN - 1] = '\0';
printf("Response:\n%s\n", response_buf); printf("Response:\n%s\n", response_buf);
free(request_buf); free(request_buf);
...@@ -2290,6 +2293,8 @@ int startMultiThreadCreateChildTable( ...@@ -2290,6 +2293,8 @@ int startMultiThreadCreateChildTable(
g_Dbs.port); g_Dbs.port);
if (t_info->taos == NULL) { if (t_info->taos == NULL) {
fprintf(stderr, "Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL)); fprintf(stderr, "Failed to connect to TDengine, reason:%s\n", taos_errstr(NULL));
free(pids);
free(infos);
return -1; return -1;
} }
t_info->start_table_id = last; t_info->start_table_id = last;
...@@ -2342,8 +2347,8 @@ static void createChildTables() { ...@@ -2342,8 +2347,8 @@ static void createChildTables() {
} else { } else {
// normal table // normal table
len = snprintf(tblColsBuf, MAX_SQL_SIZE, "(TS TIMESTAMP"); len = snprintf(tblColsBuf, MAX_SQL_SIZE, "(TS TIMESTAMP");
for (int i = 0; i < MAX_COLUMN_COUNT; i++) { int i = 0;
if (g_args.datatype[i]) { while (g_args.datatype[i]) {
if ((strncasecmp(g_args.datatype[i], "BINARY", strlen("BINARY")) == 0) if ((strncasecmp(g_args.datatype[i], "BINARY", strlen("BINARY")) == 0)
|| (strncasecmp(g_args.datatype[i], "NCHAR", strlen("NCHAR")) == 0)) { || (strncasecmp(g_args.datatype[i], "NCHAR", strlen("NCHAR")) == 0)) {
len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ", COL%d %s(60)", i, g_args.datatype[i]); len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ", COL%d %s(60)", i, g_args.datatype[i]);
...@@ -2351,15 +2356,13 @@ static void createChildTables() { ...@@ -2351,15 +2356,13 @@ static void createChildTables() {
len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ", COL%d %s", i, g_args.datatype[i]); len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ", COL%d %s", i, g_args.datatype[i]);
} }
len = strlen(tblColsBuf); len = strlen(tblColsBuf);
} else {
len = snprintf(tblColsBuf + len, MAX_SQL_SIZE, ")");
break;
} }
}
len = snprintf(tblColsBuf + len, MAX_SQL_SIZE - len, ")");
debugPrint("DEBUG - %s() LN%d: %s\n", __func__, __LINE__, debugPrint("DEBUG - %s() LN%d: %s\n", __func__, __LINE__,
tblColsBuf); tblColsBuf);
startMultiThreadCreateChildTable( startMultiThreadCreateChildTable(
tblColsBuf, tblColsBuf,
g_Dbs.threadCountByCreateTbl, g_Dbs.threadCountByCreateTbl,
g_args.num_of_DPT, g_args.num_of_DPT,
...@@ -4073,11 +4076,10 @@ static void* syncWrite(void *sarg) { ...@@ -4073,11 +4076,10 @@ static void* syncWrite(void *sarg) {
int len_of_binary = g_args.len_of_binary; int len_of_binary = g_args.len_of_binary;
int ncols_per_record = 1; // count first col ts int ncols_per_record = 1; // count first col ts
for (int i = 0; i < MAX_COLUMN_COUNT; i ++) { int i = 0;
if (NULL == g_args.datatype[i]) while(g_args.datatype[i]) {
break; i ++;
else ncols_per_record ++;
ncols_per_record ++;
} }
srand((uint32_t)time(NULL)); srand((uint32_t)time(NULL));
...@@ -4558,11 +4560,14 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision, ...@@ -4558,11 +4560,14 @@ void startMultiThreadInsertData(int threads, char* db_name, char* precision,
if (0 == strncasecmp(superTblInfo->startTimestamp, "now", 3)) { if (0 == strncasecmp(superTblInfo->startTimestamp, "now", 3)) {
start_time = taosGetTimestamp(timePrec); start_time = taosGetTimestamp(timePrec);
} else { } else {
taosParseTime( if (TSDB_CODE_SUCCESS != taosParseTime(
superTblInfo->startTimestamp, superTblInfo->startTimestamp,
&start_time, &start_time,
strlen(superTblInfo->startTimestamp), strlen(superTblInfo->startTimestamp),
timePrec, 0); timePrec, 0)) {
printf("ERROR to parse time!\n");
exit(-1);
}
} }
} else { } else {
start_time = 1500000000000; start_time = 1500000000000;
......
...@@ -769,6 +769,7 @@ int32_t taosSaveTableOfMetricToTempFile(TAOS *taosCon, char* metric, struct argu ...@@ -769,6 +769,7 @@ int32_t taosSaveTableOfMetricToTempFile(TAOS *taosCon, char* metric, struct argu
} }
sprintf(tmpBuf, ".select-tbname.tmp"); sprintf(tmpBuf, ".select-tbname.tmp");
(void)remove(tmpBuf); (void)remove(tmpBuf);
free(tblBuf);
close(fd); close(fd);
return -1; return -1;
} }
...@@ -1523,6 +1524,7 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao ...@@ -1523,6 +1524,7 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao
} }
sprintf(tmpBuf, ".show-tables.tmp"); sprintf(tmpBuf, ".show-tables.tmp");
(void)remove(tmpBuf); (void)remove(tmpBuf);
free(tblBuf);
close(fd); close(fd);
return -1; return -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册