From dd62128662bb6b0651985c166934667a5117cf31 Mon Sep 17 00:00:00 2001 From: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com> Date: Tue, 7 May 2024 11:01:16 +0800 Subject: [PATCH] Add compiler warning check in the CI workflow (#177) * Add compiler warning check in the CI workflow and fix compiler warning in the implementation --------- Co-authored-by: ActoryOu --- .github/.cSpellWords.txt | 5 +++++ .github/workflows/ci.yml | 5 +++++ source/core_http_client.c | 14 ++++++++------ test/CMakeLists.txt | 15 ++++++++++++--- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/.cSpellWords.txt b/.github/.cSpellWords.txt index 37112fdc..93840b88 100644 --- a/.github/.cSpellWords.txt +++ b/.github/.cSpellWords.txt @@ -49,4 +49,9 @@ utest vect Vect VECT +Wconversion +Werror +Weverything +Wextra +Wpedantic Wunused diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1444471d..7efe576a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,10 +16,15 @@ jobs: - name: Build run: | sudo apt-get install -y lcov + + # Build the coverity analysis project as well to check compiler warning. + # Coverity analysis project builds coreHTTP source file only. llhttp source + # files are not built in this target. cmake -S test -B build/ \ -G "Unix Makefiles" \ -DCMAKE_BUILD_TYPE=Debug \ -DUNITTEST=1 \ + -DCOV_ANALYSIS=1 \ -DCMAKE_C_FLAGS='--coverage -Wall -Wextra -DNDEBUG' make -C build/ all diff --git a/source/core_http_client.c b/source/core_http_client.c index 7a1ddc49..42578475 100644 --- a/source/core_http_client.c +++ b/source/core_http_client.c @@ -545,12 +545,12 @@ static int8_t caseInsensitiveStringCmp( const char * str1, /* Subtract offset to go from lowercase to uppercase ASCII character */ if( ( firstChar >= 'a' ) && ( firstChar <= 'z' ) ) { - firstChar = firstChar - offset; + firstChar = ( char ) ( firstChar - offset ); } if( ( secondChar >= 'a' ) && ( secondChar <= 'z' ) ) { - secondChar = secondChar - offset; + secondChar = ( char ) ( secondChar - offset ); } if( ( firstChar ) != ( secondChar ) ) @@ -1249,6 +1249,7 @@ static uint8_t convertInt32ToAscii( int32_t value, uint8_t numOfDigits = 0U; uint8_t index = 0U; uint8_t isNegative = 0U; + int32_t bufferIndex; char temp = '\0'; assert( pBuffer != NULL ); @@ -1263,7 +1264,7 @@ static uint8_t convertInt32ToAscii( int32_t value, *pBuffer = '-'; /* Convert the value to its absolute representation. */ - absoluteValue = value * -1; + absoluteValue = value * ( -1 ); } /* Write the absolute integer value in reverse ASCII representation. */ @@ -1279,11 +1280,12 @@ static uint8_t convertInt32ToAscii( int32_t value, for( index = 0U; index < ( numOfDigits / 2U ); index++ ) { temp = pBuffer[ isNegative + index ]; - pBuffer[ isNegative + index ] = pBuffer[ isNegative + numOfDigits - index - 1U ]; - pBuffer[ isNegative + numOfDigits - index - 1U ] = temp; + bufferIndex = ( int32_t ) isNegative + ( int32_t ) numOfDigits - ( int32_t ) index - 1; + pBuffer[ isNegative + index ] = pBuffer[ bufferIndex ]; + pBuffer[ bufferIndex ] = temp; } - return( isNegative + numOfDigits ); + return ( uint8_t ) ( isNegative + numOfDigits ); } /*-----------------------------------------------------------*/ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 66c4873a..d8e02404 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -44,7 +44,7 @@ if( COV_ANALYSIS ) # Target for Coverity analysis that builds the library. add_library( coverity_analysis - ${HTTP_SOURCES} ) + ${CMAKE_CURRENT_LIST_DIR}/../source/core_http_client.c ) # Build HTTP library target without custom config dependency. target_compile_definitions( coverity_analysis PUBLIC HTTP_DO_NOT_USE_CUSTOM_CONFIG=1 ) @@ -52,8 +52,17 @@ if( COV_ANALYSIS ) # HTTP public include path. target_include_directories( coverity_analysis PUBLIC ${HTTP_INCLUDE_PUBLIC_DIRS} ) - # Build HTTP library target without logging - target_compile_options(coverity_analysis PUBLIC -DNDEBUG ) + target_compile_options( coverity_analysis PUBLIC + # Build HTTP library target without logging + -DNDEBUG + + # GCC compiler option + -Wall + -Wextra + -Wpedantic + -Wconversion + -Werror + ) endif() # ===================== Clone needed third-party libraries ======================