From 89aa04debb96498cb96dac9ec1e2578052b30510 Mon Sep 17 00:00:00 2001 From: Hui Li Date: Thu, 18 Jun 2020 15:27:08 +0800 Subject: [PATCH 01/11] [modify for coverity scan] --- src/util/inc/tutil.h | 2 ++ src/util/src/tcache.c | 2 +- src/util/src/tconfig.c | 9 +++++++-- src/util/src/tdes.c | 2 +- src/util/src/tlog.c | 17 ++++++++++++----- src/util/src/tnote.c | 12 +++++++++--- src/util/src/tskiplist.c | 2 +- src/util/src/tutil.c | 31 +++++++++++++++++++++++++++---- 8 files changed, 60 insertions(+), 17 deletions(-) diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index d38f983718..ddb7c04094 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -116,6 +116,8 @@ extern "C" { #define POW2(x) ((x) * (x)) +int taosRand(void); + int32_t strdequote(char *src); size_t strtrim(char *src); diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 7aaa5b91db..48603a014e 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -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; } diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index 2288035fc7..bcea8d1654 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -119,8 +119,13 @@ static void taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { struct stat dirstat; if (stat(option, &dirstat) < 0) { int code = mkdir(option, 0755); - uPrint("config option:%s, input value:%s, directory not exist, create with return code:%d", - cfg->option, input_value, code); + 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 { diff --git a/src/util/src/tdes.c b/src/util/src/tdes.c index 3112fb4111..c76938d3aa 100644 --- a/src/util/src/tdes.c +++ b/src/util/src/tdes.c @@ -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; } } diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index d1fb287184..39ec89daf4 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -233,7 +233,9 @@ static void taosGetLogFileName(char *fn) { } } - strcpy(tsLogObj.logName, 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); - strcpy(name, fn); - strcat(name, ".0"); + 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 { - strcpy(name, fn); - strcat(name, ".1"); + if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) { + strcpy(name, fn); + strcat(name, ".1"); + } + if (stat(name, &logstat1) < 0) { tsLogObj.flag = 1; } else { diff --git a/src/util/src/tnote.c b/src/util/src/tnote.c index 5bb120d4c6..a8d9e8d416 100644 --- a/src/util/src/tnote.c +++ b/src/util/src/tnote.c @@ -169,7 +169,9 @@ void taosGetNoteName(char *fn, taosNoteInfo * pNote) } } - strcpy(pNote->taosNoteName, fn); + 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, ¬estat0) < 0) { pNote->taosNoteFlag = 0; - } - else { + } else { strcpy(name, fn); strcat(name, ".1"); if (stat(name, ¬estat1) < 0) { diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index f1f3481865..4872c9298a 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -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++; } diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 3b92cf21ee..61082b85e3 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -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); - strcat(tmpPath, fileNamePrefix); - strcat(tmpPath, "-%d-%s"); + 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]; } } @@ -718,4 +741,4 @@ void taosRemoveDir(char *rootDir) { rmdir(rootDir); uPrint("dir:%s is removed", rootDir); -} \ No newline at end of file +} From 4f6973d6ec81a434dc144013fdebb19c975391fa Mon Sep 17 00:00:00 2001 From: Hui Li Date: Thu, 18 Jun 2020 15:44:58 +0800 Subject: [PATCH 02/11] [modify for coverity scan] --- src/util/src/tutil.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 61082b85e3..644200b0b2 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -40,10 +40,17 @@ int taosRand(void) 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); + if (fd < 0) { + seed = time(0); + } else { + int len = read(fd, &seed, sizeof(seed)); + if (len < 0) { + seed = time(0); + } + srand(seed); + close(fd); + } - srand(seed); return rand(); } #endif From bee2818b5a55d376f357c893afdb8df171f9342d Mon Sep 17 00:00:00 2001 From: Hui Li Date: Thu, 18 Jun 2020 16:01:06 +0800 Subject: [PATCH 03/11] [modify for coverity scan] --- src/util/src/tutil.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 644200b0b2..a2edce2387 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -37,7 +37,7 @@ int taosRand(void) int taosRand(void) { int fd; - unsigned long seed; + int seed; fd = open("/dev/urandom", 0); if (fd < 0) { @@ -46,12 +46,11 @@ int taosRand(void) int len = read(fd, &seed, sizeof(seed)); if (len < 0) { seed = time(0); - } - srand(seed); + } close(fd); } - - return rand(); + + return seed; } #endif From c31efb7044002295bd4542771228eb680e3cb92f Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 18 Jun 2020 16:45:26 +0800 Subject: [PATCH 04/11] [td-225] update script --- tests/script/general/parser/null_char.sim | 201 +++++++++++----------- 1 file changed, 103 insertions(+), 98 deletions(-) diff --git a/tests/script/general/parser/null_char.sim b/tests/script/general/parser/null_char.sim index 6da419cd4c..bbb8dd4448 100644 --- a/tests/script/general/parser/null_char.sim +++ b/tests/script/general/parser/null_char.sim @@ -206,68 +206,71 @@ endi ################# binary sql alter table st41 set tag tag_binary = "shanghai" -sql describe st41 -if $data23 != shanghai then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data00 != shanghai then return -1 endi + ##### test 'space' case -#$tagvalue = ' -#$tagvalue = $tagvalue ' -#sql alter table st41 set tag tag_binary = $tagvalue +$tagvalue = '' +$tagvalue = $tagvalue ' sql alter table st41 set tag tag_binary = "" -#sql describe st41 -#if $data23 != $tagvalue then -# return -1 -#endi -sql alter table st41 set tag tag_binary = "NULL" -sql describe st41 -if $data23 != NULL then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data00 != @@ then + print expect , actual $data00 return -1 endi + +sql alter table st41 set tag tag_binary = "NULL" +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data00 != NULL then + return -1 +endi + sql alter table st41 set tag tag_binary = NULL -sql describe st41 -if $data23 != NULL then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data00 != NULL then print ==8== expect: NULL, actually: $data23 return -1 endi ################### nchar sql alter table st41 set tag tag_nchar = "��˼����" -sql describe st41 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 #sleep 1000 -#if $data33 != ��˼���� then -# print ==== expect ��˼����, actually $data33 +#if $data01 != ��˼���� then +# print ==== expect ��˼����, actually $data01 # return -1 #endi ##### test 'space' case #$tagvalue = ' #$tagvalue = $tagvalue ' sql alter table st41 set tag tag_nchar = '' -#sql describe st41 -#if $data33 != $tagvalue then +#sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +#if $data01 != $tagvalue then # return -1 #endi sql alter table st41 set tag tag_nchar = "NULL" -sql describe st41 -if $data33 != NULL then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data01 != NULL then return -1 endi sql alter table st41 set tag tag_nchar = NULL -#sql describe st41 -#if $data33 != then -# print ==9== expect , actually $data33 +#sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +#if $data01 != then +# print ==9== expect , actually $data01 # return -1 #endi ################### int sql alter table st41 set tag tag_int = -2147483647 -sql describe st41 -if $data43 != -2147483647 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data02 != -2147483647 then return -1 endi sql alter table st41 set tag tag_int = 2147483647 -sql describe st41 -if $data43 != 2147483647 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data02 != 2147483647 then return -1 endi @@ -275,19 +278,19 @@ sql_error alter table st41 set tag tag_int = -2147483648 sql_error alter table st41 set tag tag_int = 2147483648 sql alter table st41 set tag tag_int = '-379' -sql describe st41 -if $data43 != -379 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data02 != -379 then return -1 endi sql alter table st41 set tag tag_int = -2000 -sql describe st41 -if $data43 != -2000 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data02 != -2000 then return -1 endi sql alter table st41 set tag tag_int = NULL -sql describe st41 -if $data43 != NULL then - print ==10== expect: NULL, actually: $data43 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data02 != NULL then + print ==10== expect: NULL, actually: $data02 return -1 endi sql alter table st41 set tag tag_int = 'NULL' @@ -296,34 +299,34 @@ sql_error alter table st41 set tag tag_int = abc379 ################### bool sql alter table st41 set tag tag_bool = 'true' -sql describe st41 -if $data53 != true then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data03 != 1 then return -1 endi sql alter table st41 set tag tag_bool = 'false' -sql describe st41 -if $data53 != false then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data03 != 0 then return -1 endi sql alter table st41 set tag tag_bool = 0 -sql describe st41 -if $data53 != false then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data03 != 0 then return -1 endi sql alter table st41 set tag tag_bool = 123 -sql describe st41 -if $data53 != true then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data03 != 1 then return -1 endi sql alter table st41 set tag tag_bool = 'NULL' -sql describe st41 -if $data53 != NULL then - print ==14== expect: NULL, actually: $data53 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data03 != NULL then + print ==14== expect: NULL, actually: $data03 return -1 endi sql alter table st41 set tag tag_bool = NULL -sql describe st41 -if $data53 != NULL then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data03 != NULL then return -1 endi @@ -333,50 +336,51 @@ sql_error alter table st41 set tag tag_bool = abc379 ################### float sql alter table st41 set tag tag_float = -32 -sql describe st41 -if $data63 != -32.000000 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != -32.00000 then + print expect -32.00000 actual $data04 return -1 endi sql alter table st41 set tag tag_float = 54.123456 -sql describe st41 -if $data63 != 54.123455 then - print ==15== expect: 54.123455, actually: $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != 54.123455 then + print ==15== expect: 54.123455, actually: $data04 # return -1 endi sql alter table st41 set tag tag_float = 54.12345 -sql describe st41 -if $data63 != 54.123451 then - print ==16== expect: 54.123451, actually: $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != 54.12345 then + print ==16== expect: 54.12345, actually: $data04 return -1 endi sql alter table st41 set tag tag_float = 54.12345678 -sql describe st41 -if $data63 != 54.123455 then - print ==11== expect: 54.123455, actually : $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != 54.12346 then + print ==11== expect: 54.12346, actually : $data04 return -1 endi sql alter table st41 set tag tag_float = NULL -sql describe st41 -if $data63 != NULL then - print ==12== expect: NULL, actually : $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != NULL then + print ==12== expect: NULL, actually : $data04 return -1 endi sql alter table st41 set tag tag_float = 'NULL' -sql describe st41 -if $data63 != NULL then - print ==17== expect: NULL, actually : $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != NULL then + print ==17== expect: NULL, actually : $data04 return -1 endi sql alter table st41 set tag tag_float = '54.123456' -sql describe st41 -if $data63 != 54.123455 then - print ==18== expect: 54.123455, actually : $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != 54.12346 then + print ==18== expect: 54.12346, actually : $data04 return -1 endi sql alter table st41 set tag tag_float = '-54.123456' -sql describe st41 -if $data63 != -54.123455 then - print ==19== expect: -54.123455, actually : $data63 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data04 != -54.12346 then + print ==19== expect: -54.12346, actually : $data04 return -1 endi sql_error alter table st41 set tag tag_float = '' @@ -387,30 +391,32 @@ sql_error alter table st41 set tag tag_float = abc ################### double sql alter table st41 set tag tag_double = -92 -sql describe st41 -if $data73 != -92.000000 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data05 != -92.000000000 then + print expect -92.000000000 actual $data05 return -1 endi sql alter table st41 set tag tag_double = 184 -sql describe st41 -if $data73 != 184.000000 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data05 != 184.000000000 then + print expect 184.000000000 actual $data05 return -1 endi sql alter table st41 set tag tag_double = '-2456' -sql describe st41 -if $data73 != -2456.000000 then +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data05 != -2456.000000000 then return -1 endi sql alter table st41 set tag tag_double = NULL -sql describe st41 -if $data73 != NULL then - print ==13== expect: NULL, actually : $data73 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data05 != NULL then + print ==13== expect: NULL, actually : $data05 return -1 endi sql alter table st41 set tag tag_double = 'NULL' -sql describe st41 -if $data73 != NULL then - print ==20== expect: NULL, actually : $data73 +sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 +if $data05 != NULL then + print ==20== expect: NULL, actually : $data05 return -1 endi sql_error alter table st41 set tag tag_double = '' @@ -427,23 +433,22 @@ sql alter table st51 set tag tag_bigint = '-379' sql alter table st51 set tag tag_bigint = -2000 sql alter table st51 set tag tag_bigint = NULL sql alter table st51 set tag tag_bigint = 9223372036854775807 -sql describe st51 -if $data23 != 9223372036854775807 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data00 != 9223372036854775807 then return -1 endi sql alter table st51 set tag tag_bigint = 9223372036854775808 -sql describe st51 -if $data23 != 9223372036854775807 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data00 != 9223372036854775807 then return -1 endi sql alter table st51 set tag tag_bigint = -9223372036854775807 -sql describe st51 -if $data23 != -9223372036854775807 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data00 != -9223372036854775807 then return -1 endi sql_error alter table st51 set tag tag_bigint = -9223372036854775808 - sql alter table st51 set tag tag_bigint = 'NULL' sql_error alter table st51 set tag tag_bigint = '' sql_error alter table st51 set tag tag_bigint = abc379 @@ -452,15 +457,15 @@ sql_error alter table st51 set tag tag_bigint = abc379 sql alter table st51 set tag tag_smallint = -2000 sql alter table st51 set tag tag_smallint = NULL sql alter table st51 set tag tag_smallint = 32767 -sql describe st51 -if $data33 != 32767 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data01 != 32767 then return -1 endi sql_error alter table st51 set tag tag_smallint = 32768 sql alter table st51 set tag tag_smallint = -32767 -sql describe st51 -if $data33 != -32767 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data01 != -32767 then return -1 endi sql_error alter table st51 set tag tag_smallint = -32768 @@ -473,13 +478,13 @@ sql_error alter table st51 set tag tag_smallint = abc379 sql alter table st51 set tag tag_tinyint = -127 sql alter table st51 set tag tag_tinyint = NULL sql alter table st51 set tag tag_tinyint = 127 -sql describe st51 -if $data43 != 127 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data02 != 127 then return -1 endi sql alter table st51 set tag tag_tinyint = -127 -sql describe st51 -if $data43 != -127 then +sql select tag_bigint, tag_smallint, tag_tinyint from st51 +if $data02 != -127 then return -1 endi sql_error alter table st51 set tag tag_tinyint = '-128' From e83fd5043ad3d377b37f56b8a27addf131f6111e Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Thu, 18 Jun 2020 14:10:27 +0800 Subject: [PATCH 05/11] fix some coverity issues --- src/client/src/TSDBJNIConnector.c | 2 +- src/client/src/tscServer.c | 14 ++++++-------- src/client/src/tscSql.c | 7 ++++++- src/client/src/tscStream.c | 6 +++--- src/client/src/tscSub.c | 8 +++++--- src/client/src/tscSubquery.c | 4 ++-- src/client/src/tscUtil.c | 4 ++-- 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index a9a34286a8..dc44c8ea26 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -192,7 +192,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions(JNIEnv const char *tz1 = (*env)->GetStringUTFChars(env, optionValue, NULL); if (tz1 && strlen(tz1) != 0) { res = taos_options(TSDB_OPTION_TIMEZONE, tz1); - jniTrace("set timezone to %s, result:%d", timezone, res); + jniTrace("set timezone to %s, result:%d", tz1, res); } else { jniTrace("input timezone is empty"); } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 5a2054bbcd..da807b1964 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -646,10 +646,6 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { size_t numOfOutput = tscSqlExprNumOfExprs(pQueryInfo); pQueryMsg->numOfOutput = htons(numOfOutput); - if (numOfOutput < 0) { - tscError("%p illegal value of number of output columns in query msg: %d", pSql, numOfOutput); - return -1; - } // set column list ids size_t numOfCols = taosArrayGetSize(pQueryInfo->colList); @@ -663,7 +659,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { if (pCol->colIndex.columnIndex >= tscGetNumOfColumns(pTableMeta) || pColSchema->type < TSDB_DATA_TYPE_BOOL || pColSchema->type > TSDB_DATA_TYPE_NCHAR) { tscError("%p sid:%d uid:%" PRIu64" id:%s, column index out of range, numOfColumns:%d, index:%d, column name:%s", - pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex, + pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex.columnIndex, pColSchema->name); return TSDB_CODE_TSC_INVALID_SQL; @@ -783,7 +779,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { (pColSchema->type < TSDB_DATA_TYPE_BOOL || pColSchema->type > TSDB_DATA_TYPE_NCHAR)) { tscError("%p sid:%d uid:%" PRIu64 " id:%s, tag index out of range, totalCols:%d, numOfTags:%d, index:%d, column name:%s", pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, total, numOfTagColumns, - pCol->colIndex, pColSchema->name); + pCol->colIndex.columnIndex, pColSchema->name); return TSDB_CODE_TSC_INVALID_SQL; } @@ -982,7 +978,7 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCMDropDbMsg *pDropDbMsg = (SCMDropDbMsg*)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); - strncpy(pDropDbMsg->db, pTableMetaInfo->name, tListLen(pDropDbMsg->db)); + tstrncpy(pDropDbMsg->db, pTableMetaInfo->name, sizeof(pDropDbMsg->db)); pDropDbMsg->ignoreNotExists = pInfo->pDCLInfo->existsCheck ? 1 : 0; pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_DB; @@ -1052,7 +1048,7 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0); - strcpy(pDropMsg->user, pTableMetaInfo->name); + tstrncpy(pDropMsg->user, pTableMetaInfo->name, sizeof(pDropMsg->user)); return TSDB_CODE_SUCCESS; } @@ -1812,6 +1808,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { // todo handle out of memory case if (pTableMetaInfo->pTableMeta == NULL) { + free(pTableMeta); return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -2324,6 +2321,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) { SQueryInfo *pNewQueryInfo = NULL; if ((code = tscGetQueryInfoDetailSafely(&pNew->cmd, 0, &pNewQueryInfo)) != TSDB_CODE_SUCCESS) { + tscFreeSqlObj(pNew); return code; } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 126e34704c..b13e7b7ccf 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -584,7 +584,7 @@ char *taos_errstr(TAOS_RES *tres) { void taos_config(int debug, char *log_path) { uDebugFlag = debug; - strcpy(tsLogDir, log_path); + tstrncpy(tsLogDir, log_path, TSDB_FILENAME_LEN); } char *taos_get_server_info(TAOS *taos) { @@ -719,6 +719,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { if (sqlLen > tsMaxSQLStringLen) { tscError("%p sql too long", pSql); pRes->code = TSDB_CODE_TSC_INVALID_SQL; + tfree(pSql); return pRes->code; } @@ -727,6 +728,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to malloc sql string buffer", pSql); tscTrace("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj); + tfree(pSql); return pRes->code; } @@ -851,6 +853,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { if (tblListLen > MAX_TABLE_NAME_LENGTH) { tscError("%p tableNameList too long, length:%d, maximum allowed:%d", pSql, tblListLen, MAX_TABLE_NAME_LENGTH); pRes->code = TSDB_CODE_TSC_INVALID_SQL; + tfree(pSql); return pRes->code; } @@ -858,6 +861,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { if (str == NULL) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to malloc sql string buffer", pSql); + tfree(pSql); return pRes->code; } @@ -873,6 +877,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { free(str); if (pRes->code != TSDB_CODE_SUCCESS) { + tscFreeSqlObj(pSql); return pRes->code; } diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index 7ce86dc1a4..6fc934b6c0 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -125,7 +125,7 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) { } // launch stream computing in a new thread - SSchedMsg schedMsg; + SSchedMsg schedMsg = { 0 }; schedMsg.fp = tscProcessStreamLaunchQuery; schedMsg.ahandle = pStream; schedMsg.thandle = (void *)1; @@ -239,7 +239,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf /* no resuls in the query range, retry */ // todo set retry dynamic time int32_t retry = tsProjectExecInterval; - tscError("%p stream:%p, retrieve no data, code:%d, retry in %" PRId64 "ms", pSql, pStream, numOfRows, retry); + tscError("%p stream:%p, retrieve no data, code:%d, retry in %" PRId32 "ms", pSql, pStream, numOfRows, retry); tscSetRetryTimer(pStream, pStream->pSql, retry); return; @@ -250,7 +250,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf } } - tscTrace("%p stream:%p, query on:%s, fetch result completed, fetched rows:%d", pSql, pStream, pTableMetaInfo->name, + tscTrace("%p stream:%p, query on:%s, fetch result completed, fetched rows:%" PRId64, pSql, pStream, pTableMetaInfo->name, pStream->numOfRes); // release the metric/meter meta information reference, so data in cache can be updated diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 7e3aaf7fc5..15dc58a713 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -291,7 +291,7 @@ static int tscLoadSubscriptionProgress(SSub* pSub) { fclose(fp); taosArraySort(progress, tscCompareSubscriptionProgress); - tscTrace("subscription progress loaded, %d tables: %s", taosArrayGetSize(progress), pSub->topic); + tscTrace("subscription progress loaded, %z tables: %s", taosArrayGetSize(progress), pSub->topic); return 1; } @@ -350,7 +350,7 @@ TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char pSub->interval = interval; if (fp != NULL) { - tscTrace("asynchronize subscription, create new timer", topic); + tscTrace("asynchronize subscription, create new timer: %s", topic); pSub->fp = fp; pSub->param = param; taosTmrReset(tscProcessSubscriptionTimer, interval, pSub, tscTmr, &pSub->pTimer); @@ -435,7 +435,9 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) { } else { char path[256]; sprintf(path, "%s/subscribe/%s", tsDataDir, pSub->topic); - remove(path); + if (remove(path) != 0) { + tscError("failed to remove progress file, topic = %s, error = %s", pSub->topic, strerror(errno)); + } } tscFreeSqlObj(pSub->pSql); diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index d25afcf00f..6cba2a08a3 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1703,7 +1703,7 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR pRes->numOfRows, pState->numOfRetrievedRows, pSql->ipList.fqdn[pSql->ipList.inUse], idx); if (num > tsMaxNumOfOrderedResults && tscIsProjectionQueryOnSTable(pQueryInfo, 0)) { - tscError("%p sub:%p num of OrderedRes is too many, max allowed:%" PRId64 " , current:%" PRId64, + tscError("%p sub:%p num of OrderedRes is too many, max allowed:%" PRId32 " , current:%" PRId64, pPObj, pSql, tsMaxNumOfOrderedResults, num); tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_SORTED_RES_TOO_MANY); return; @@ -1728,6 +1728,7 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR pRes->numOfRows, pQueryInfo->groupbyExpr.orderType); if (ret < 0) { // set no disk space error info, and abort retry tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_NO_DISKSPACE); + pthread_mutex_unlock(&trsupport->queryMutex); } else if (pRes->completed) { tscAllDataRetrievedFromDnode(trsupport, pSql); @@ -1738,7 +1739,6 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR taos_fetch_rows_a(tres, tscRetrieveFromDnodeCallBack, param); } - pthread_mutex_unlock(&trsupport->queryMutex); } else { // all data has been retrieved to client tscAllDataRetrievedFromDnode(trsupport, pSql); } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 01f2bb7dd5..9a2e028dd1 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1840,7 +1840,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void size_t size = taosArrayGetSize(pNewQueryInfo->colList); tscTrace( - "%p new subquery:%p, tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%d, colList:%d," + "%p new subquery:%p, tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%z, colList:%z," "fieldInfo:%d, name:%s, qrang:%" PRId64 " - %" PRId64 " order:%d, limit:%" PRId64, pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo), size, pNewQueryInfo->fieldsInfo.numOfOutput, pFinalInfo->name, pNewQueryInfo->window.skey, @@ -2002,7 +2002,7 @@ void tscTryQueryNextVnode(SSqlObj* pSql, __async_cb_func_t fp) { int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups; while (++pTableMetaInfo->vgroupIndex < totalVgroups) { - tscTrace("%p results from vgroup index:%d completed, try next:%d. total vgroups:%d. current numOfRes:%d", pSql, + tscTrace("%p results from vgroup index:%d completed, try next:%d. total vgroups:%d. current numOfRes:%" PRId64, pSql, pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups, pRes->numOfClauseTotal); /* From b7bee06a1816a8d5895f009cdc0447b70cf206ab Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Thu, 18 Jun 2020 16:14:25 +0800 Subject: [PATCH 06/11] fix coverity issues continue --- src/client/src/tscSchemaUtil.c | 1 - src/client/src/tscSubquery.c | 57 ++++++++++++++++++---------------- src/client/src/tscSystem.c | 4 +-- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/client/src/tscSchemaUtil.c b/src/client/src/tscSchemaUtil.c index 0dfbf8c487..da06e3e5e2 100644 --- a/src/client/src/tscSchemaUtil.c +++ b/src/client/src/tscSchemaUtil.c @@ -32,7 +32,6 @@ int32_t tscGetNumOfTags(const STableMeta* pTableMeta) { } if (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE) { - assert(tinfo.numOfTags >= 0); return tinfo.numOfTags; } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 6cba2a08a3..b0a66701c5 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -354,7 +354,7 @@ static int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) { } size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList); - tscTrace("%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s", + tscTrace("%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%z, colList:%z, fieldsInfo:%d, name:%s", pSql, pNew, 0, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, taosArrayGetSize(pNewQueryInfo->exprList), numOfCols, pNewQueryInfo->fieldsInfo.numOfOutput, pTableMetaInfo->name); } @@ -551,7 +551,7 @@ static void issueTSCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj* tscTrace( "%p subquery:%p tableIndex:%d, vgroupIndex:%d, numOfVgroups:%d, type:%d, ts_comp query to retrieve timestamps, " - "numOfExpr:%d, colList:%d, numOfOutputFields:%d, name:%s", + "numOfExpr:%z, colList:%z, numOfOutputFields:%d, name:%s", pParent, pSql, 0, pTableMetaInfo->vgroupIndex, pTableMetaInfo->vgroupList->numOfVgroups, pQueryInfo->type, tscSqlExprNumOfExprs(pQueryInfo), numOfCols, pQueryInfo->fieldsInfo.numOfOutput, pTableMetaInfo->name); @@ -713,28 +713,31 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow if (taosArrayGetSize(s1) == 0 || taosArrayGetSize(s2) == 0) { // no results,return. tscTrace("%p free all sub SqlObj and quit", pParentSql); freeJoinSubqueryObj(pParentSql); - return; + + } else { + // proceed to for ts_comp query + SSqlCmd* pSubCmd1 = &pParentSql->pSubs[0]->cmd; + SSqlCmd* pSubCmd2 = &pParentSql->pSubs[1]->cmd; + + SQueryInfo* pQueryInfo1 = tscGetQueryInfoDetail(pSubCmd1, 0); + STableMetaInfo* pTableMetaInfo1 = tscGetMetaInfo(pQueryInfo1, 0); + tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo1, s1); + + SQueryInfo* pQueryInfo2 = tscGetQueryInfoDetail(pSubCmd2, 0); + STableMetaInfo* pTableMetaInfo2 = tscGetMetaInfo(pQueryInfo2, 0); + tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo2, s2); + + pSupporter->pState->numOfTotal = 2; + pSupporter->pState->numOfRemain = pSupporter->pState->numOfTotal; + + for (int32_t m = 0; m < pParentSql->numOfSubs; ++m) { + SSqlObj* sub = pParentSql->pSubs[m]; + issueTSCompQuery(sub, sub->param, pParentSql); + } } - // proceed to for ts_comp query - SSqlCmd* pSubCmd1 = &pParentSql->pSubs[0]->cmd; - SSqlCmd* pSubCmd2 = &pParentSql->pSubs[1]->cmd; - - SQueryInfo* pQueryInfo1 = tscGetQueryInfoDetail(pSubCmd1, 0); - STableMetaInfo* pTableMetaInfo1 = tscGetMetaInfo(pQueryInfo1, 0); - tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo1, s1); - - SQueryInfo* pQueryInfo2 = tscGetQueryInfoDetail(pSubCmd2, 0); - STableMetaInfo* pTableMetaInfo2 = tscGetMetaInfo(pQueryInfo2, 0); - tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo2, s2); - - pSupporter->pState->numOfTotal = 2; - pSupporter->pState->numOfRemain = pSupporter->pState->numOfTotal; - - for (int32_t m = 0; m < pParentSql->numOfSubs; ++m) { - SSqlObj* sub = pParentSql->pSubs[m]; - issueTSCompQuery(sub, sub->param, pParentSql); - } + taosArrayDestroy(s1); + taosArrayDestroy(s2); } static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRows) { @@ -1242,7 +1245,7 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter tscTrace( "%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, transfer to tid_tag query to retrieve (tableId, tags), " - "exprInfo:%d, colList:%d, fieldsInfo:%d, tagIndex:%d, name:%s", + "exprInfo:%z, colList:%z, fieldsInfo:%d, tagIndex:%d, name:%s", pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo), numOfCols, pNewQueryInfo->fieldsInfo.numOfOutput, index.columnIndex, pNewQueryInfo->pTableMetaInfo[0]->name); } else { @@ -1276,8 +1279,8 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList); tscTrace( - "%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, transfer to ts_comp query to retrieve timestamps, " - "exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s", + "%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%u, transfer to ts_comp query to retrieve timestamps, " + "exprInfo:%z, colList:%z, fieldsInfo:%d, name:%s", pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo), numOfCols, pNewQueryInfo->fieldsInfo.numOfOutput, pNewQueryInfo->pTableMetaInfo[0]->name); } @@ -1699,7 +1702,7 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR assert(pRes->numOfRows == numOfRows); int64_t num = atomic_add_fetch_64(&pState->numOfRetrievedRows, numOfRows); - tscTrace("%p sub:%p retrieve numOfRows:%d totalNumOfRows:%d from ip:%s, orderOfSub:%d", pPObj, pSql, + tscTrace("%p sub:%p retrieve numOfRows:%" PRId64 " totalNumOfRows:%" PRIu64 " from ip:%s, orderOfSub:%d", pPObj, pSql, pRes->numOfRows, pState->numOfRetrievedRows, pSql->ipList.fqdn[pSql->ipList.inUse], idx); if (num > tsMaxNumOfOrderedResults && tscIsProjectionQueryOnSTable(pQueryInfo, 0)) { @@ -1827,7 +1830,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) { } if (pParentSql->res.code != TSDB_CODE_SUCCESS) { // at least one peer subquery failed, abort current query - tscTrace("%p sub:%p query failed,ip:%u,vgId:%d,orderOfSub:%d,global code:%d", pParentSql, pSql, + tscTrace("%p sub:%p query failed,ip:%s,vgId:%d,orderOfSub:%d,global code:%d", pParentSql, pSql, pVgroup->ipAddr[0].fqdn, pVgroup->vgId, trsupport->subqueryIndex, pParentSql->res.code); tscHandleSubqueryError(param, tres, pParentSql->res.code); diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index bcd01a322e..a653b83833 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -220,7 +220,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { if (strlen(tsLocale) == 0) { // locale does not set yet char* defaultLocale = setlocale(LC_CTYPE, ""); - strcpy(tsLocale, defaultLocale); + tstrncpy(tsLocale, defaultLocale, sizeof(tsLocale)); } // set the user specified locale @@ -304,7 +304,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { assert(cfg != NULL); if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { - strcpy(tsTimezone, pStr); + tstrncpy(tsTimezone, pStr, sizeof(tsTimezone)); tsSetTimeZone(); cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; tscTrace("timezone set:%s, input:%s by taos_options", tsTimezone, pStr); From ccd9cde5d15da03136ad910bf9986d786e8ba050 Mon Sep 17 00:00:00 2001 From: plum-lihui <2849823933@qq.com> Date: Thu, 18 Jun 2020 17:22:43 +0800 Subject: [PATCH 07/11] Construct an empty result for later result checking --- tests/script/general/parser/null_char.sim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/script/general/parser/null_char.sim b/tests/script/general/parser/null_char.sim index bbb8dd4448..09e761c85e 100644 --- a/tests/script/general/parser/null_char.sim +++ b/tests/script/general/parser/null_char.sim @@ -212,12 +212,11 @@ if $data00 != shanghai then endi ##### test 'space' case -$tagvalue = '' -$tagvalue = $tagvalue ' +system_content echo ' ' | sed 's/ //g' | tr -d '\n' # Construct an empty result for later result checking sql alter table st41 set tag tag_binary = "" sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41 -if $data00 != @@ then - print expect , actual $data00 +if $data00 != $system_content then + print expect [ $system_content ], actual [ $data00 ] return -1 endi @@ -498,4 +497,4 @@ sql_error alter table st51 set tag tag_tinyint = abc379 #sql drop database $db -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT From ac0f08da90c5432ba316f1a35cd1450c031edb33 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 18 Jun 2020 17:49:18 +0800 Subject: [PATCH 08/11] scripts --- src/client/src/tscUtil.c | 2 +- tests/script/jenkins/basic.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 9a2e028dd1..e65c9a8bdf 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1840,7 +1840,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void size_t size = taosArrayGetSize(pNewQueryInfo->colList); tscTrace( - "%p new subquery:%p, tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%z, colList:%z," + "%p new subquery:%p, tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%zu, colList:%zu," "fieldInfo:%d, name:%s, qrang:%" PRId64 " - %" PRId64 " order:%d, limit:%" PRId64, pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo), size, pNewQueryInfo->fieldsInfo.numOfOutput, pFinalInfo->name, pNewQueryInfo->window.skey, diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 673022e0c6..79cb1551e1 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -120,7 +120,7 @@ cd ../../../debug; make #./test.sh -f general/parser/import_file.sim ./test.sh -f general/parser/lastrow.sim ./test.sh -f general/parser/nchar.sim -#./test.sh -f general/parser/null_char.sim +./test.sh -f general/parser/null_char.sim ./test.sh -f general/parser/single_row_in_tb.sim ./test.sh -f general/parser/select_from_cache_disk.sim ./test.sh -f general/parser/mixed_blocks.sim From fa8af0d9961b7f48e2340d2ba796014e74650fe0 Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Thu, 18 Jun 2020 09:55:47 +0000 Subject: [PATCH 09/11] dont reset lockedBy --- src/rpc/src/rpcMain.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 989021eb52..365857a14e 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -574,19 +574,13 @@ static void rpcReleaseConn(SRpcConn *pConn) { char hashstr[40] = {0}; size_t size = snprintf(hashstr, sizeof(hashstr), "%x:%x:%x:%d", pConn->peerIp, pConn->linkUid, pConn->peerId, pConn->connType); taosHashRemove(pRpc->hash, hashstr, size); - rpcFreeMsg(pConn->pRspMsg); // it may have a response msg saved, but not request msg - pConn->pRspMsg = NULL; - pConn->inType = 0; - pConn->inTranId = 0; - } else { - pConn->outType = 0; - pConn->outTranId = 0; - pConn->pReqMsg = NULL; - } + } taosFreeId(pRpc->idPool, pConn->sid); - pConn->pContext = NULL; + int64_t lockedBy = pConn->lockedBy; + memset(pConn, 0, sizeof(SRpcConn)); + pConn->lockedBy = lockedBy; tTrace("%s, rpc connection is released", pConn->info); } @@ -611,7 +605,6 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) { terrno = TSDB_CODE_RPC_MAX_SESSIONS; } else { pConn = pRpc->connList + sid; - memset(pConn, 0, sizeof(SRpcConn)); pConn->pRpc = pRpc; pConn->sid = sid; From a61552783544ca3c1f6c70392475a1e30b31a51c Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Thu, 18 Jun 2020 10:03:33 +0000 Subject: [PATCH 10/11] free ID in the last step --- src/rpc/src/rpcMain.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 365857a14e..71e1651ce1 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -576,11 +576,12 @@ static void rpcReleaseConn(SRpcConn *pConn) { taosHashRemove(pRpc->hash, hashstr, size); rpcFreeMsg(pConn->pRspMsg); // it may have a response msg saved, but not request msg } - - taosFreeId(pRpc->idPool, pConn->sid); + + int sid = pConn->sid; int64_t lockedBy = pConn->lockedBy; memset(pConn, 0, sizeof(SRpcConn)); pConn->lockedBy = lockedBy; + taosFreeId(pRpc->idPool, sid); tTrace("%s, rpc connection is released", pConn->info); } From ff16a84d59490dce236ede2de66acf81071ca139 Mon Sep 17 00:00:00 2001 From: Jeff Tao Date: Thu, 18 Jun 2020 10:07:06 +0000 Subject: [PATCH 11/11] add comments --- src/rpc/src/rpcMain.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 71e1651ce1..4a28cb4ff4 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -577,6 +577,7 @@ static void rpcReleaseConn(SRpcConn *pConn) { rpcFreeMsg(pConn->pRspMsg); // it may have a response msg saved, but not request msg } + // lockedBy can not be reset, since it maybe hold by a thread int sid = pConn->sid; int64_t lockedBy = pConn->lockedBy; memset(pConn, 0, sizeof(SRpcConn));