From 77c6f616f9784ecaa7ac562abd3cb58b8fe5909b Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Tue, 7 Apr 2020 14:39:31 +0800 Subject: [PATCH] add compile flag to treat all warnings as errors. [TD-118] --- cmake/platform.inc | 14 +++++++------- src/client/src/tscSchemaUtil.c | 4 ++-- src/client/src/tscSub.c | 14 ++++++-------- src/common/src/name.c | 4 ++-- src/inc/taosmsg.h | 4 ++-- src/mnode/inc/mgmtGrant.h | 2 +- src/query/inc/tlosertree.h | 2 +- src/query/src/queryExecutor.c | 5 +++-- src/query/src/tlosertree.c | 2 +- src/util/src/tskiplist.c | 4 ++-- 10 files changed, 27 insertions(+), 28 deletions(-) diff --git a/cmake/platform.inc b/cmake/platform.inc index 0d53f0cc43..6087b6f16f 100755 --- a/cmake/platform.inc +++ b/cmake/platform.inc @@ -107,12 +107,12 @@ IF (TD_LINUX_64) SET(RELEASE_FLAGS "-O0") IF (NOT TD_ARM) IF (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") - SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g3 -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -g3 -gdwarf-2 -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") ELSE () - SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g3 -gdwarf-2 -malign-stringops -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -malign-double -g3 -gdwarf-2 -malign-stringops -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") ENDIF () ELSE () - SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -g -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g -fsigned-char -fpack-struct=8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") ENDIF () ADD_DEFINITIONS(-DLINUX) ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT) @@ -128,7 +128,7 @@ IF (TD_LINUX_64) ENDIF () SET(DEBUG_FLAGS "-O0 -DDEBUG") SET(RELEASE_FLAGS "-O0") - SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -g -fsigned-char -munaligned-access -fpack-struct=8 -latomic -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -fPIC -g -fsigned-char -munaligned-access -fpack-struct=8 -latomic -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") ADD_DEFINITIONS(-DLINUX) ADD_DEFINITIONS(-D_REENTRANT -D__USE_POSIX -D_LIBC_REENTRANT) ADD_DEFINITIONS(-DUSE_LIBICONV) @@ -141,7 +141,7 @@ IF (TD_LINUX_64) ELSEIF (TD_WINDOWS_64) SET(CMAKE_GENERATOR "NMake Makefiles" CACHE INTERNAL "" FORCE) IF (NOT TD_GODLL) - SET(COMMON_FLAGS "/nologo /WX- /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-") + SET(COMMON_FLAGS "/nologo /WX /Oi /Oy- /Gm- /EHsc /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Gd /errorReport:prompt /analyze-") SET(DEBUG_FLAGS "/Zi /W3 /GL") SET(RELEASE_FLAGS "/W0 /GL") ENDIF () @@ -151,7 +151,7 @@ IF (TD_LINUX_64) ADD_DEFINITIONS(-DPTW32_BUILD) ADD_DEFINITIONS(-D_MBCS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) ELSEIF (TD_DARWIN_64) - SET(COMMON_FLAGS "-std=gnu99 -Wall -fPIC -malign-double -g -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") + SET(COMMON_FLAGS "-std=gnu99 -Wall -Werror -Wno-missing-braces -fPIC -g -msse4.2 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILE") SET(DEBUG_FLAGS "-O0 -DDEBUG") SET(RELEASE_FLAGS "-O0") ADD_DEFINITIONS(-DDARWIN) @@ -159,4 +159,4 @@ IF (TD_LINUX_64) ELSE () MESSAGE(FATAL_ERROR "The current platform is not support yet, stop compile") EXIT () - ENDIF () \ No newline at end of file + ENDIF () diff --git a/src/client/src/tscSchemaUtil.c b/src/client/src/tscSchemaUtil.c index b487d5d6db..90e1bd4c1d 100644 --- a/src/client/src/tscSchemaUtil.c +++ b/src/client/src/tscSchemaUtil.c @@ -210,7 +210,7 @@ char* tsGetTagsValue(STableMeta* pTableMeta) { } // todo refactor -static FORCE_INLINE char* skipSegments(char* input, char delim, int32_t num) { +__attribute__ ((unused))static FORCE_INLINE char* skipSegments(char* input, char delim, int32_t num) { for (int32_t i = 0; i < num; ++i) { while (*input != 0 && *input++ != delim) { }; @@ -218,7 +218,7 @@ static FORCE_INLINE char* skipSegments(char* input, char delim, int32_t num) { return input; } -static FORCE_INLINE size_t copy(char* dst, const char* src, char delimiter) { +__attribute__ ((unused)) static FORCE_INLINE size_t copy(char* dst, const char* src, char delimiter) { size_t len = 0; while (*src != delimiter && *src != 0) { *dst++ = *src++; diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index fd457a12dd..b7d01941d6 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -108,7 +108,7 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* if (pSql == NULL) { terrno = TSDB_CODE_CLI_OUT_OF_MEMORY; tscError("failed to allocate SSqlObj for subscription"); - goto failed; + goto _pSql_failed; } pSql->signature = pSql; @@ -137,13 +137,11 @@ static SSub* tscCreateSubscription(STscObj* pObj, const char* topic, const char* return pSub; failed: - if (sqlstr != NULL) { - free(sqlstr); - } - if (pSql != NULL) { - free(pSql); - } - free(pSub); + tfree(sqlstr); + +_pSql_failed: + tfree(pSql); + tfree(pSub); return NULL; } diff --git a/src/common/src/name.c b/src/common/src/name.c index b0411d742c..a605b98a14 100644 --- a/src/common/src/name.c +++ b/src/common/src/name.c @@ -6,7 +6,7 @@ #include "ttokendef.h" // todo refactor -static FORCE_INLINE const char* skipSegments(const char* input, char delim, int32_t num) { +__attribute__((unused)) static FORCE_INLINE const char* skipSegments(const char* input, char delim, int32_t num) { for (int32_t i = 0; i < num; ++i) { while (*input != 0 && *input++ != delim) { }; @@ -14,7 +14,7 @@ static FORCE_INLINE const char* skipSegments(const char* input, char delim, int3 return input; } -static FORCE_INLINE size_t copy(char* dst, const char* src, char delimiter) { +__attribute__((unused)) static FORCE_INLINE size_t copy(char* dst, const char* src, char delimiter) { size_t len = 0; while (*src != delimiter && *src != 0) { *dst++ = *src++; diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 5550ebf177..3fae17170a 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -753,12 +753,12 @@ typedef struct { typedef struct { int32_t numOfQueries; - SQueryDesc qdesc[]; + SQueryDesc *qdesc; } SQqueryList; typedef struct { int32_t numOfStreams; - SStreamDesc sdesc[]; + SStreamDesc *sdesc; } SStreamList; typedef struct { diff --git a/src/mnode/inc/mgmtGrant.h b/src/mnode/inc/mgmtGrant.h index c9e018d9b5..92b20532c4 100644 --- a/src/mnode/inc/mgmtGrant.h +++ b/src/mnode/inc/mgmtGrant.h @@ -14,7 +14,7 @@ */ #ifndef TDENGINE_MGMT_GRANT_H -#define TDENGINE_MGMT_GTANT_H +#define TDENGINE_MGMT_GRANT_H #ifdef __cplusplus "C" { diff --git a/src/query/inc/tlosertree.h b/src/query/inc/tlosertree.h index fb64fd2ee4..197d27a761 100644 --- a/src/query/inc/tlosertree.h +++ b/src/query/inc/tlosertree.h @@ -38,7 +38,7 @@ typedef struct SLoserTreeInfo { SLoserTreeNode *pNode; } SLoserTreeInfo; -uint8_t tLoserTreeCreate(SLoserTreeInfo **pTree, int32_t numOfEntries, void *param, __merge_compare_fn_t compareFn); +uint32_t tLoserTreeCreate(SLoserTreeInfo **pTree, int32_t numOfEntries, void *param, __merge_compare_fn_t compareFn); void tLoserTreeInit(SLoserTreeInfo *pTree); diff --git a/src/query/src/queryExecutor.c b/src/query/src/queryExecutor.c index edb0e0aaed..f0aa13ee3d 100644 --- a/src/query/src/queryExecutor.c +++ b/src/query/src/queryExecutor.c @@ -5707,7 +5707,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou SArray *pTableIdList) { SQInfo *pQInfo = (SQInfo *)calloc(1, sizeof(SQInfo)); if (pQInfo == NULL) { - goto _clean_memory; + goto _clean_pQInfo_memory; } SQuery *pQuery = calloc(1, sizeof(SQuery)); @@ -5836,6 +5836,7 @@ _clean_memory: tfree(pExprs); tfree(pGroupbyExpr); +_clean_pQInfo_memory: tfree(pQInfo); return NULL; @@ -6213,4 +6214,4 @@ int32_t qDumpRetrieveResult(SQInfo *pQInfo, SRetrieveTableRsp** pRsp, int32_t* c // vnodeDecRefCount(pObj->qhandle); // pObj->qhandle = NULL; // } -} \ No newline at end of file +} diff --git a/src/query/src/tlosertree.c b/src/query/src/tlosertree.c index 4fe68970b9..e6e45ed8d0 100644 --- a/src/query/src/tlosertree.c +++ b/src/query/src/tlosertree.c @@ -40,7 +40,7 @@ void tLoserTreeDisplay(SLoserTreeInfo* pTree) { printf("\n"); } -uint8_t tLoserTreeCreate(SLoserTreeInfo** pTree, int32_t numOfEntries, void* param, __merge_compare_fn_t compareFn) { +uint32_t tLoserTreeCreate(SLoserTreeInfo** pTree, int32_t numOfEntries, void* param, __merge_compare_fn_t compareFn) { int32_t totalEntries = numOfEntries << 1; *pTree = (SLoserTreeInfo*)calloc(1, sizeof(SLoserTreeInfo) + sizeof(SLoserTreeNode) * totalEntries); diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index 3af7bfd2f2..0ef99b7244 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -18,7 +18,7 @@ #include "tskiplist.h" #include "tutil.h" -static FORCE_INLINE void recordNodeEachLevel(SSkipList *pSkipList, int32_t level) { // record link count in each level +__attribute__ ((unused)) static FORCE_INLINE void recordNodeEachLevel(SSkipList *pSkipList, int32_t level) { // record link count in each level #if SKIP_LIST_RECORD_PERFORMANCE for (int32_t i = 0; i < level; ++i) { pSkipList->state.nLevelNodeCnt[i]++; @@ -26,7 +26,7 @@ static FORCE_INLINE void recordNodeEachLevel(SSkipList *pSkipList, int32_t level #endif } -static FORCE_INLINE void removeNodeEachLevel(SSkipList *pSkipList, int32_t level) { +__attribute__ ((unused)) static FORCE_INLINE void removeNodeEachLevel(SSkipList *pSkipList, int32_t level) { #if SKIP_LIST_RECORD_PERFORMANCE for (int32_t i = 0; i < level; ++i) { pSkipList->state.nLevelNodeCnt[i]--;