diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f50aca0797cb2d3a2b61796d43137fb417f76ee..fe2cc6b42ebe6661bdf942428757e8a19aef25ba 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,13 +42,6 @@ INCLUDE(cmake/env.inc) INCLUDE(cmake/version.inc) INCLUDE(cmake/install.inc) -IF (CMAKE_SYSTEM_NAME MATCHES "Linux") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -Wall -Wshadow -Werror") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe -Wall -Wshadow -Werror") -ENDIF () -MESSAGE(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") -MESSAGE(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") - ADD_SUBDIRECTORY(deps) ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(tests) diff --git a/cmake/define.inc b/cmake/define.inc index d6a3f2b915fca1a766c06abc412eb8ce60522ef0..dc3ea3a0b274c852eab048c172aac3b8a5758511 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -178,7 +178,7 @@ IF (TD_WINDOWS) MESSAGE("memory sanitizer detected as false") SET(DEBUG_FLAGS "/Zi /W3 /GL") ENDIF () - SET(RELEASE_FLAGS "/W0 /O3 /GL") + SET(RELEASE_FLAGS "/W0 /O2 /GL") # MSVC only support O2 ENDIF () INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/pthread) @@ -201,6 +201,10 @@ IF (TD_WINDOWS_32) MESSAGE(STATUS "windows32 is defined") ENDIF () +IF (TD_LINUX) + SET(COMMON_FLAGS "${COMMON_FLAGS} -pipe -Wshadow") +ENDIF () + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index 891dccaf9779016065013d4f59580026fb98352a..04b1efe7bf78d57a8806960995b0e34ff79e3abb 100644 --- a/src/os/src/detail/osSysinfo.c +++ b/src/os/src/detail/osSysinfo.c @@ -74,13 +74,14 @@ bool taosGetProcMemory(float *memoryUsedMB) { return false; } + ssize_t _bytes = 0; size_t len; char * line = NULL; while (!feof(fp)) { tfree(line); len = 0; - getline(&line, &len, fp); - if (line == NULL) { + _bytes = getline(&line, &len, fp); + if ((_bytes < 0) || (line == NULL)) { break; } if (strstr(line, "VmRSS:") != NULL) { @@ -113,8 +114,8 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { size_t len; char * line = NULL; - getline(&line, &len, fp); - if (line == NULL) { + ssize_t _bytes = getline(&line, &len, fp); + if ((_bytes < 0) || (line == NULL)) { uError("read file:%s failed", tsSysCpuFile); fclose(fp); return false; @@ -138,8 +139,8 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { size_t len = 0; char * line = NULL; - getline(&line, &len, fp); - if (line == NULL) { + ssize_t _bytes = getline(&line, &len, fp); + if ((_bytes < 0) || (line == NULL)) { uError("read file:%s failed", tsProcCpuFile); fclose(fp); return false; @@ -339,6 +340,7 @@ static bool taosGetCardInfo(int64_t *bytes) { return false; } + ssize_t _bytes = 0; size_t len = 2048; char * line = calloc(1, len); @@ -357,7 +359,12 @@ static bool taosGetCardInfo(int64_t *bytes) { int64_t nouse6 = 0; char nouse0[200] = {0}; - getline(&line, &len, fp); + _bytes = getline(&line, &len, fp); + if (_bytes < 0) + { + break; + } + line[len - 1] = 0; if (strstr(line, "lo:") != NULL) { @@ -420,6 +427,7 @@ static bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) { return false; } + ssize_t _bytes = 0; size_t len; char * line = NULL; char tmp[10]; @@ -428,8 +436,8 @@ static bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) { while (!feof(fp)) { tfree(line); len = 0; - getline(&line, &len, fp); - if (line == NULL) { + _bytes = getline(&line, &len, fp); + if ((_bytes < 0) || (line == NULL)) { break; } if (strstr(line, "rchar:") != NULL) { diff --git a/src/plugins/http/src/httpJson.c b/src/plugins/http/src/httpJson.c index df4c4fbc63d469c22ea13273564bec49562f35a9..10300e93670b5e10f56259d51b6ca31df3e90e39 100644 --- a/src/plugins/http/src/httpJson.c +++ b/src/plugins/http/src/httpJson.c @@ -297,6 +297,7 @@ void httpJsonTimestamp(JsonBuf* buf, int64_t t, int32_t timePrecision) { } default: + fractionLen = 0; assert(false); } @@ -342,6 +343,7 @@ void httpJsonUtcTimestamp(JsonBuf* buf, int64_t t, int32_t timePrecision) { } default: + fractionLen = 0; assert(false); } diff --git a/src/util/src/tbuffer.c b/src/util/src/tbuffer.c index abfa35f42cc9798d3a8a7dd7d6b874705ace88ba..c06d1e59bd537bc009b462f0b17b9cdd00321d20 100644 --- a/src/util/src/tbuffer.c +++ b/src/util/src/tbuffer.c @@ -18,6 +18,24 @@ #include "exception.h" #include "taoserror.h" +typedef union Un4B { + uint32_t ui; + float f; +} Un4B; +#if __STDC_VERSION__ >= 201112L +static_assert(sizeof(Un4B) == sizeof(uint32_t), "sizeof(Un4B) must equal to sizeof(uint32_t)"); +static_assert(sizeof(Un4B) == sizeof(float), "sizeof(Un4B) must equal to sizeof(float)"); +#endif + +typedef union Un8B { + uint64_t ull; + double d; +} Un8B; +#if __STDC_VERSION__ >= 201112L +static_assert(sizeof(Un8B) == sizeof(uint64_t), "sizeof(Un8B) must equal to sizeof(uint64_t)"); +static_assert(sizeof(Un8B) == sizeof(double), "sizeof(Un8B) must equal to sizeof(double)"); +#endif + //////////////////////////////////////////////////////////////////////////////// // reader functions @@ -175,13 +193,21 @@ uint64_t tbufReadUint64( SBufferReader* buf ) { } float tbufReadFloat( SBufferReader* buf ) { - uint32_t ret = tbufReadUint32( buf ); - return *(float*)( &ret ); + Un4B _un; + tbufReadToBuffer( buf, &_un, sizeof(_un) ); + if( buf->endian ) { + _un.ui = ntohl( _un.ui ); + } + return _un.f; } double tbufReadDouble(SBufferReader* buf) { - uint64_t ret = tbufReadUint64( buf ); - return *(double*)( &ret ); + Un8B _un; + tbufReadToBuffer( buf, &_un, sizeof(_un) ); + if( buf->endian ) { + _un.ull = htobe64( _un.ull ); + } + return _un.d; } //////////////////////////////////////////////////////////////////////////////// @@ -381,17 +407,37 @@ void tbufWriteUint64At( SBufferWriter* buf, size_t pos, uint64_t data ) { } void tbufWriteFloat( SBufferWriter* buf, float data ) { - tbufWriteUint32( buf, *(uint32_t*)(&data) ); + Un4B _un; + _un.f = data; + if( buf->endian ) { + _un.ui = htonl( _un.ui ); + } + tbufWrite( buf, &_un, sizeof(_un) ); } void tbufWriteFloatAt( SBufferWriter* buf, size_t pos, float data ) { - tbufWriteUint32At( buf, pos, *(uint32_t*)(&data) ); + Un4B _un; + _un.f = data; + if( buf->endian ) { + _un.ui = htonl( _un.ui ); + } + tbufWriteAt( buf, pos, &_un, sizeof(_un) ); } void tbufWriteDouble( SBufferWriter* buf, double data ) { - tbufWriteUint64( buf, *(uint64_t*)(&data) ); + Un8B _un; + _un.d = data; + if( buf->endian ) { + _un.ull = htobe64( _un.ull ); + } + tbufWrite( buf, &_un, sizeof(_un) ); } void tbufWriteDoubleAt( SBufferWriter* buf, size_t pos, double data ) { - tbufWriteUint64At( buf, pos, *(uint64_t*)(&data) ); + Un8B _un; + _un.d = data; + if( buf->endian ) { + _un.ull = htobe64( _un.ull ); + } + tbufWriteAt( buf, pos, &_un, sizeof(_un) ); } diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index 442e83bb4f76499d7ce39792fc188d61536910c2..30d53af4b978c1c697a3ac892bad9b279af1252c 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -327,7 +327,8 @@ void taosReadGlobalLogCfg() { printf("\nconfig file:%s not found, all variables are set to default\n", fileName); return; } - + + ssize_t _bytes = 0; size_t len = 1024; line = calloc(1, len); @@ -337,7 +338,12 @@ void taosReadGlobalLogCfg() { option = value = NULL; olen = vlen = 0; - tgetline(&line, &len, fp); + _bytes = tgetline(&line, &len, fp); + if (_bytes < 0) + { + break; + } + line[len - 1] = 0; paGetToken(line, &option, &olen); @@ -373,7 +379,8 @@ bool taosReadGlobalCfg() { return false; } } - + + ssize_t _bytes = 0; size_t len = 1024; line = calloc(1, len); @@ -383,7 +390,12 @@ bool taosReadGlobalCfg() { option = value = value2 = value3 = NULL; olen = vlen = vlen2 = vlen3 = 0; - tgetline(&line, &len, fp); + _bytes = tgetline(&line, &len, fp); + if (_bytes < 0) + { + break; + } + line[len - 1] = 0; paGetToken(line, &option, &olen); diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index bda52936f90d07b1fde598de9ca683c8a1b8b82a..1a73991ade1ea4617fc4d3dab3904652ff46d691 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -427,13 +427,23 @@ char *taosIpStr(uint32_t ipInt) { } FORCE_INLINE float taos_align_get_float(const char* pBuf) { - float fv = 0; - *(int32_t*)(&fv) = *(int32_t*)pBuf; +#if __STDC_VERSION__ >= 201112L + static_assert(sizeof(float) == sizeof(uint32_t), "sizeof(float) must equal to sizeof(uint32_t)"); +#else + assert(sizeof(float) == sizeof(uint32_t)); +#endif + float fv = 0; + memcpy(&fv, pBuf, sizeof(fv)); // in ARM, return *((const float*)(pBuf)) may cause problem return fv; } FORCE_INLINE double taos_align_get_double(const char* pBuf) { - double dv = 0; - *(int64_t*)(&dv) = *(int64_t*)pBuf; +#if __STDC_VERSION__ >= 201112L + static_assert(sizeof(double) == sizeof(uint64_t), "sizeof(double) must equal to sizeof(uint64_t)"); +#else + assert(sizeof(double) == sizeof(uint64_t)); +#endif + double dv = 0; + memcpy(&dv, pBuf, sizeof(dv)); // in ARM, return *((const double*)(pBuf)) may cause problem return dv; }