From 6e01c527a612bd65b0f19c0ac5ff79df36212493 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Fri, 11 Oct 2019 14:33:42 +0800 Subject: [PATCH] supress some warnings from clang-tidy,valgrind etc. --- src/inc/sdb.h | 2 +- src/inc/tglobalcfg.h | 26 +++++++++---------- src/inc/tlog.h | 13 ++++------ src/inc/trpc.h | 1 - src/inc/ttimer.h | 2 +- src/os/linux/inc/os.h | 10 ++++++++ src/rpc/src/trpc.c | 2 +- src/sdb/inc/sdbint.h | 1 - src/util/src/tcompression.c | 48 ++++++++++++++-------------------- src/util/src/textbuffer.c | 8 ++++-- src/util/src/tglobalcfg.c | 20 +++++++-------- src/util/src/tlog.c | 2 +- src/util/src/tskiplist.c | 1 - src/util/src/ttimer.c | 6 ++--- src/util/src/ttokenizer.c | 9 ++++--- src/util/src/ttypes.c | 51 ++++++++++++++++++++----------------- src/util/src/tutil.c | 11 +++++++- 17 files changed, 113 insertions(+), 100 deletions(-) diff --git a/src/inc/sdb.h b/src/inc/sdb.h index 39416a3216..b1c07054ca 100644 --- a/src/inc/sdb.h +++ b/src/inc/sdb.h @@ -23,7 +23,7 @@ extern "C" { #include "taosmsg.h" #include "tsdb.h" -extern int sdbDebugFlag; +extern uint32_t sdbDebugFlag; extern short sdbPeerPort; extern short sdbSyncPort; extern int sdbMaxNodes; diff --git a/src/inc/tglobalcfg.h b/src/inc/tglobalcfg.h index 4bdbe2ad00..cfc89997d3 100644 --- a/src/inc/tglobalcfg.h +++ b/src/inc/tglobalcfg.h @@ -146,19 +146,19 @@ extern char tsInternalPass[]; extern int tsMonitorInterval; extern int tsNumOfLogLines; -extern int ddebugFlag; -extern int mdebugFlag; -extern int cdebugFlag; -extern int jnidebugFlag; -extern int tmrDebugFlag; -extern int sdbDebugFlag; -extern int httpDebugFlag; -extern int monitorDebugFlag; -extern int uDebugFlag; -extern int rpcDebugFlag; -extern int debugFlag; -extern int odbcdebugFlag; -extern int qdebugFlag; +extern uint32_t ddebugFlag; +extern uint32_t mdebugFlag; +extern uint32_t cdebugFlag; +extern uint32_t jnidebugFlag; +extern uint32_t tmrDebugFlag; +extern uint32_t sdbDebugFlag; +extern uint32_t httpDebugFlag; +extern uint32_t monitorDebugFlag; +extern uint32_t uDebugFlag; +extern uint32_t rpcDebugFlag; +extern uint32_t debugFlag; +extern uint32_t odbcdebugFlag; +extern uint32_t qdebugFlag; extern int tsRpcTimer; extern int tsRpcMaxTime; diff --git a/src/inc/tlog.h b/src/inc/tlog.h index c6e4c82ca1..0d348c27ce 100644 --- a/src/inc/tlog.h +++ b/src/inc/tlog.h @@ -25,16 +25,14 @@ extern "C" { #include #include "tglobalcfg.h" -#define DEBUG_ERROR 1 -#define DEBUG_WARN 2 -#define DEBUG_TRACE 4 -#define DEBUG_DUMP 8 +#define DEBUG_ERROR 1U +#define DEBUG_WARN 2U +#define DEBUG_TRACE 4U +#define DEBUG_DUMP 8U #define DEBUG_FILE 0x80 #define DEBUG_SCREEN 0x40 -extern int uDebugFlag; - extern void (*taosLogFp)(int level, const char *const format, ...); extern void (*taosLogSqlFp)(char *sql); @@ -99,7 +97,7 @@ void taosResetLogFile(); { tprintf("UTL ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); } // client log function -extern int cdebugFlag; +extern uint32_t cdebugFlag; #define tscError(...) \ if (cdebugFlag & DEBUG_ERROR) { \ @@ -132,7 +130,6 @@ extern int cdebugFlag; { tprintf("JNI ", 255, __VA_ARGS__); } // rpc log function -extern int rpcDebugFlag; #define tError(...) \ if (rpcDebugFlag & DEBUG_ERROR) { \ tprintf("ERROR RPC ", rpcDebugFlag, __VA_ARGS__); \ diff --git a/src/inc/trpc.h b/src/inc/trpc.h index 991ea08d92..70804903e3 100644 --- a/src/inc/trpc.h +++ b/src/inc/trpc.h @@ -73,7 +73,6 @@ typedef struct { char * ckey; // ciphering key } SRpcConnInit; -extern int rpcDebugFlag; extern int tsRpcHeadSize; void *taosOpenRpc(SRpcInit *pRpc); diff --git a/src/inc/ttimer.h b/src/inc/ttimer.h index 91e4ffa3dd..f8e4c0140c 100644 --- a/src/inc/ttimer.h +++ b/src/inc/ttimer.h @@ -22,7 +22,7 @@ extern "C" { typedef void *tmr_h; -extern int tmrDebugFlag; +extern uint32_t tmrDebugFlag; extern int taosTmrThreads; void *taosTmrInit(int maxTmr, int resoultion, int longest, char *label); diff --git a/src/os/linux/inc/os.h b/src/os/linux/inc/os.h index 002d0be4ca..033f1dd8c5 100644 --- a/src/os/linux/inc/os.h +++ b/src/os/linux/inc/os.h @@ -39,10 +39,13 @@ #include #include #include +#include #include #include #include #include +#include +#include #include bool taosCheckPthreadValid(pthread_t thread); @@ -65,4 +68,11 @@ void taosKillSystem(); bool taosIsRunningWSLv1(); +int64_t str2int64(char *str); + +#define BUILDIN_CLZL(val) __builtin_clzl(val) +#define BUILDIN_CLZ(val) __builtin_clz(val) +#define BUILDIN_CTZL(val) __builtin_ctzl(val) +#define BUILDIN_CTZ(val) __builtin_ctz(val) + #endif \ No newline at end of file diff --git a/src/rpc/src/trpc.c b/src/rpc/src/trpc.c index d3d467afd1..2c009343ae 100644 --- a/src/rpc/src/trpc.c +++ b/src/rpc/src/trpc.c @@ -116,7 +116,7 @@ typedef struct rpc_server { } STaosRpc; // configurable -int rpcDebugFlag = 131; +uint32_t rpcDebugFlag = 131; int tsRpcTimer = 300; int tsRpcMaxTime = 600; // seconds; int tsRpcProgressTime = 10; // milliseocnds diff --git a/src/sdb/inc/sdbint.h b/src/sdb/inc/sdbint.h index 6e020bde9c..3327c1f731 100644 --- a/src/sdb/inc/sdbint.h +++ b/src/sdb/inc/sdbint.h @@ -136,7 +136,6 @@ typedef struct { extern SSdbTable *tableList[]; extern int sdbMaxPeers; -extern int sdbDebugFlag; extern int sdbNumOfTables; extern int64_t sdbVersion; diff --git a/src/util/src/tcompression.c b/src/util/src/tcompression.c index 1ec7cab1b3..cd69f30c3f 100644 --- a/src/util/src/tcompression.c +++ b/src/util/src/tcompression.c @@ -19,42 +19,31 @@ * To compress integers (including char, short, int, int64_t), the difference * between two integers is calculated at first. Then the difference is * transformed to positive by zig-zag encoding method - * (https://gist.github.com/mfuerstenau/ba870a29e16536fdbaba). Then the value - * is + * (https://gist.github.com/mfuerstenau/ba870a29e16536fdbaba). Then the value is * encoded using simple 8B method. For more information about simple 8B, * refer to https://en.wikipedia.org/wiki/8b/10b_encoding. * - * NOTE : For bigint, only 59 bits can be used, which means data from -(2**59) - * to (2**59)-1 + * NOTE : For bigint, only 59 bits can be used, which means data from -(2**59) to (2**59)-1 * are allowed. * * BOOLEAN Compression Algorithm: - * We provide two methods for compress boolean types. Because boolean types in - * C - * code are char bytes with 0 and 1 values only, only one bit can used to - * discrimenate + * We provide two methods for compress boolean types. Because boolean types in C + * code are char bytes with 0 and 1 values only, only one bit can used to discrimenate * the values. - * 1. The first method is using only 1 bit to represent the boolean value with - * 1 for + * 1. The first method is using only 1 bit to represent the boolean value with 1 for * true and 0 for false. Then the compression rate is 1/8. - * 2. The second method is using run length encoding (RLE) methods. This - * methos works + * 2. The second method is using run length encoding (RLE) methods. This methos works * better when there are a lot of consecutive true values or false values. * * STRING Compression Algorithm: * We us LZ4 method to compress the string type. * * FLOAT Compression Algorithm: - * We use the same method with Akumuli to compress float and double types. The - * compression - * algorithm assumes the float/double values change slightly. So we take the - * XOR between two - * adjacent values. Then compare the number of leading zeros and trailing - * zeros. If the number - * of leading zeros are larger than the trailing zeros, then record the last - * serveral bytes - * of the XORed value with informations. If not, record the first - * corresponding bytes. + * We use the same method with Akumuli to compress float and double types. The compression + * algorithm assumes the float/double values change slightly. So we take the XOR between two + * adjacent values. Then compare the number of leading zeros and trailing zeros. If the number + * of leading zeros are larger than the trailing zeros, then record the last serveral bytes + * of the XORed value with informations. If not, record the first corresponding bytes. * */ #include @@ -64,6 +53,7 @@ #include #include +#include "os.h" #include "lz4.h" #include "tscompression.h" #include "tsdb.h" @@ -368,7 +358,7 @@ int tsCompressINTImp(const char *const input, const int nelements, char *const o // Take care here, __builtin_clzl give wrong anser for value 0; tmp_bit = 0; } else { - tmp_bit = (LONG_BYTES * BITS_PER_BYTE) - __builtin_clzl(zigzag_value); + tmp_bit = (LONG_BYTES * BITS_PER_BYTE) - BUILDIN_CLZL(zigzag_value); } if (elems + 1 <= selector_to_elems[selector] && elems + 1 <= selector_to_elems[bit_to_selector[tmp_bit]]) { @@ -695,14 +685,14 @@ int tsCompressTimestampImp(const char *const input, const int nelements, char *c if (dd1 == 0) { flag1 = 0; } else { - flag1 = LONG_BYTES - __builtin_clzl(dd1) / BITS_PER_BYTE; + flag1 = LONG_BYTES - BUILDIN_CLZL(dd1) / BITS_PER_BYTE; } } else { dd2 = zigzag_value; if (dd2 == 0) { flag2 = 0; } else { - flag2 = LONG_BYTES - __builtin_clzl(dd2) / BITS_PER_BYTE; + flag2 = LONG_BYTES - BUILDIN_CLZL(dd2) / BITS_PER_BYTE; } flags = flag1 | (flag2 << 4); // Encode the flag. @@ -869,8 +859,8 @@ int tsCompressDoubleImp(const char *const input, const int nelements, char *cons int trailing_zeros = leading_zeros; if (diff) { - trailing_zeros = __builtin_ctzl(diff); - leading_zeros = __builtin_clzl(diff); + trailing_zeros = BUILDIN_CTZL(diff); + leading_zeros = BUILDIN_CLZL(diff); } uint8_t nbytes = 0; @@ -1016,8 +1006,8 @@ int tsCompressFloatImp(const char *const input, const int nelements, char *const int trailing_zeros = leading_zeros; if (diff) { - trailing_zeros = __builtin_ctz(diff); - leading_zeros = __builtin_clz(diff); + trailing_zeros = BUILDIN_CTZ(diff); + leading_zeros = BUILDIN_CLZ(diff); } uint8_t nbytes = 0; diff --git a/src/util/src/textbuffer.c b/src/util/src/textbuffer.c index 7c283c0f38..aa0ce9e851 100644 --- a/src/util/src/textbuffer.c +++ b/src/util/src/textbuffer.c @@ -1178,7 +1178,9 @@ void tColDataQSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta while (right > end_same && left <= end_same) { swap(pDescriptor, numOfRows, left++, data, right--); } - rightx += (end - end_same); // (pivotal+1) + steps of number that are identical pivotal + + // (pivotal+1) + steps of number that are identical pivotal + rightx += (end - end_same); #ifdef _DEBUG_VIEW tRowModelDisplay(pDescriptor, numOfRows, data, end - start + 1); @@ -1193,7 +1195,9 @@ void tColDataQSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t sta while (left < start_same && right >= start_same) { swap(pDescriptor, numOfRows, left++, data, right--); } - leftx -= (start_same - start); // (pivotal-1) - steps of number that are identical pivotal + + // (pivotal-1) - steps of number that are identical pivotal + leftx -= (start_same - start); #ifdef _DEBUG_VIEW tRowModelDisplay(pDescriptor, numOfRows, data, end - start + 1); diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c index acc2486a23..6c7e967e86 100644 --- a/src/util/src/tglobalcfg.c +++ b/src/util/src/tglobalcfg.c @@ -140,16 +140,16 @@ char tsLocale[TSDB_LOCALE_LEN] = {0}; char tsCharset[TSDB_LOCALE_LEN] = {0}; // default encode string int tsNumOfLogLines = 10000000; -int ddebugFlag = 131; -int mdebugFlag = 135; -int sdbDebugFlag = 135; -int cdebugFlag = 131; -int jnidebugFlag = 131; -int httpDebugFlag = 131; -int monitorDebugFlag = 131; -int debugFlag = 131; -int odbcdebugFlag = 131; -int qdebugFlag = 131; +uint32_t ddebugFlag = 131; +uint32_t mdebugFlag = 135; +uint32_t sdbDebugFlag = 135; +uint32_t cdebugFlag = 131; +uint32_t jnidebugFlag = 131; +uint32_t httpDebugFlag = 131; +uint32_t monitorDebugFlag = 131; +uint32_t debugFlag = 131; +uint32_t odbcdebugFlag = 131; +uint32_t qdebugFlag = 131; SGlobalConfig *tsGlobalConfig = NULL; int tsGlobalConfigNum = 0; diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index cf359a1de3..67ed23b91e 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -58,7 +58,7 @@ typedef struct { sem_t buffNotEmpty; } SLogBuff; -int uDebugFlag = 131; // all the messages +uint32_t uDebugFlag = 131; // all the messages short tsAsyncLog = 1; static SLogBuff *logHandle; diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index 81d9779daa..d7779a94af 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -242,7 +242,6 @@ tSkipList* tSkipListCreate(int16_t nMaxLevel, int16_t keyType, int16_t nMaxKeyLe srand(time(NULL)); pSkipList->state.nTotalMemSize += sizeof(tSkipList); - return pSkipList; } diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c index a89dbaebe6..cbf51747dc 100644 --- a/src/util/src/ttimer.c +++ b/src/util/src/ttimer.c @@ -95,7 +95,7 @@ typedef struct _tmr_ctrl_t { int tmrCtrlId; } tmr_ctrl_t; -int tmrDebugFlag = DEBUG_ERROR | DEBUG_WARN | DEBUG_FILE; +uint32_t tmrDebugFlag = DEBUG_ERROR | DEBUG_WARN | DEBUG_FILE; void taosTmrProcessList(tmr_ctrl_t *); tmr_ctrl_t tmrCtrl[maxNumOfTmrCtrl]; @@ -132,8 +132,8 @@ void *taosProcessAlarmSignal(void *tharg) { sigaddset(&sigset, SIGALRM); sigprocmask(SIG_BLOCK, &sigset, NULL); - timer_t timerId; - struct sigevent sevent; + timer_t timerId = {0}; + struct sigevent sevent = {0}; sevent.sigev_notify = SIGEV_THREAD_ID; sevent._sigev_un._tid = syscall(__NR_gettid); sevent.sigev_signo = SIGALRM; diff --git a/src/util/src/ttokenizer.c b/src/util/src/ttokenizer.c index 9e8f2ec535..fad7299ae6 100644 --- a/src/util/src/ttokenizer.c +++ b/src/util/src/ttokenizer.c @@ -218,6 +218,7 @@ static SKeyword keywordTable[] = { {"STABLE", TK_STABLE} }; +/* This is the hash table */ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static const char isIdChar[] = { @@ -273,11 +274,11 @@ int tSQLKeywordCode(const char* z, int n) { } /* -** Return the length of the token that begins at z[0]. -** Store the token type in *type before returning. -*/ + * Return the length of the token that begins at z[0]. + * Store the token type in *type before returning. + */ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) { - int i; + uint32_t i; switch (*z) { case ' ': case '\t': diff --git a/src/util/src/ttypes.c b/src/util/src/ttypes.c index 9f8015e6f8..eb6887d30f 100644 --- a/src/util/src/ttypes.c +++ b/src/util/src/ttypes.c @@ -25,6 +25,7 @@ #include "os.h" #include "taos.h" #include "tsdb.h" +#include "tsql.h" #include "tsqldef.h" #include "ttypes.h" #include "tutil.h" @@ -43,7 +44,7 @@ tDataDescriptor tDataTypeDesc[11] = { {TSDB_DATA_TYPE_NCHAR, 5, 8, "NCHAR"}, }; -char tTokenTypeSwitcher[] = { +char tTokenTypeSwitcher[13] = { TSDB_DATA_TYPE_NULL, // no type TSDB_DATA_TYPE_BINARY, // TK_ID TSDB_DATA_TYPE_BOOL, // TK_BOOL @@ -65,7 +66,7 @@ bool isValidDataType(int32_t type, int32_t length) { } if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { - return length >= 0 && length <= TSDB_MAX_BINARY_LEN; +// return length >= 0 && length <= TSDB_MAX_BINARY_LEN; } return true; @@ -105,8 +106,10 @@ void tVariantCreateN(tVariant *pVar, char *pz, uint32_t len, uint32_t type) { pVar->nLen = strdequote(pVar->pz); break; } - default: - assert(false); + + default: { // nType == 0 means the null value + type = TSDB_DATA_TYPE_NULL; + } } pVar->nType = type; @@ -123,56 +126,58 @@ void tVariantCreateB(tVariant *pVar, char *pz, uint32_t len, uint32_t type) { switch (type) { case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_TINYINT: { - pVar->i64Key = *(int8_t *)pz; + pVar->i64Key = GET_INT8_VAL(pz); break; } case TSDB_DATA_TYPE_SMALLINT: { - pVar->i64Key = *(int16_t *)pz; + pVar->i64Key = GET_INT16_VAL(pz); break; } case TSDB_DATA_TYPE_INT: { - pVar->i64Key = *(int32_t *)pz; + pVar->i64Key = GET_INT32_VAL(pz); break; } case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: { - pVar->i64Key = *(int64_t *)pz; + pVar->i64Key = GET_INT64_VAL(pz); break; } case TSDB_DATA_TYPE_DOUBLE: { - pVar->dKey = *(double *)pz; + pVar->dKey = GET_DOUBLE_VAL(pz); break; } case TSDB_DATA_TYPE_FLOAT: { - pVar->dKey = *(float *)pz; + pVar->dKey = GET_FLOAT_VAL(pz); break; } case TSDB_DATA_TYPE_NCHAR: { /* here we get the nchar length from raw binary bits length */ - int32_t wlen = len / TSDB_NCHAR_SIZE; - pVar->wpz = malloc((len + 1) * wlen); + pVar->nLen = len / TSDB_NCHAR_SIZE; + pVar->wpz = malloc((pVar->nLen + 1) * TSDB_NCHAR_SIZE); - wcsncpy(pVar->wpz, (wchar_t *)pz, wlen); - pVar->nLen = wlen; - pVar->wpz[wlen] = 0; + wcsncpy(pVar->wpz, (wchar_t *)pz, pVar->nLen); + pVar->wpz[pVar->nLen] = 0; break; } case TSDB_DATA_TYPE_BINARY: { pVar->pz = malloc(len + 1); strncpy(pVar->pz, pz, len); + pVar->nLen = len; pVar->pz[len] = 0; - strdequote(pVar->pz); - pVar->nLen = strlen(pVar->pz); + pVar->nLen = strdequote(pVar->pz); break; } + default: + pVar->i64Key = GET_INT32_VAL(pVar); } pVar->nType = type; } + void tVariantDestroy(tVariant *pVar) { if (pVar == NULL) return; @@ -780,29 +785,29 @@ void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems) { void assignVal(char *val, char *src, int32_t len, int32_t type) { switch (type) { case TSDB_DATA_TYPE_INT: { - *((int32_t *)val) = *(int32_t *)src; + *((int32_t *)val) = GET_INT32_VAL(src); break; } case TSDB_DATA_TYPE_FLOAT: { - *((float *)val) = *(float *)src; + *((float *)val) = GET_FLOAT_VAL(src); break; }; case TSDB_DATA_TYPE_DOUBLE: { - *((double *)val) = *(double *)src; + *((double *)val) = GET_DOUBLE_VAL(src); break; }; case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_BIGINT: { - *((int64_t *)val) = *(int64_t *)src; + *((int64_t *)val) = GET_INT64_VAL(src); break; }; case TSDB_DATA_TYPE_SMALLINT: { - *((int16_t *)val) = *(int16_t *)src; + *((int16_t *)val) = GET_INT16_VAL(src); break; }; case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_TINYINT: { - *((int8_t *)val) = *(int8_t *)src; + *((int8_t *)val) = GET_INT8_VAL(src); break; }; default: { diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index e239471b51..cb93319900 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -498,4 +498,13 @@ bool taosGetVersionNumber(char *versionStr, int *versionNubmer) { versionStr[versionNumberPos[3] - 1] = '.'; return true; -} \ No newline at end of file +} + +char *taosIpStr(int ipInt) { + static char ipStrArray[3][30]; + static int ipStrIndex = 0; + + char *ipStr = ipStrArray[(ipStrIndex++) % 3]; + sprintf(ipStr, "0x%x:%d.%d.%d.%d", ipInt, ipInt & 0xFF, (ipInt >> 8) & 0xFF, (ipInt >> 16) & 0xFF, ipInt >> 24); + return ipStr; +} -- GitLab