Skip to content

Commit dd62128

Browse files
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 <[email protected]>
1 parent 57e3570 commit dd62128

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

.github/.cSpellWords.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ utest
4949
vect
5050
Vect
5151
VECT
52+
Wconversion
53+
Werror
54+
Weverything
55+
Wextra
56+
Wpedantic
5257
Wunused

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ jobs:
1616
- name: Build
1717
run: |
1818
sudo apt-get install -y lcov
19+
20+
# Build the coverity analysis project as well to check compiler warning.
21+
# Coverity analysis project builds coreHTTP source file only. llhttp source
22+
# files are not built in this target.
1923
cmake -S test -B build/ \
2024
-G "Unix Makefiles" \
2125
-DCMAKE_BUILD_TYPE=Debug \
2226
-DUNITTEST=1 \
27+
-DCOV_ANALYSIS=1 \
2328
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -DNDEBUG'
2429
make -C build/ all
2530

source/core_http_client.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,12 +545,12 @@ static int8_t caseInsensitiveStringCmp( const char * str1,
545545
/* Subtract offset to go from lowercase to uppercase ASCII character */
546546
if( ( firstChar >= 'a' ) && ( firstChar <= 'z' ) )
547547
{
548-
firstChar = firstChar - offset;
548+
firstChar = ( char ) ( firstChar - offset );
549549
}
550550

551551
if( ( secondChar >= 'a' ) && ( secondChar <= 'z' ) )
552552
{
553-
secondChar = secondChar - offset;
553+
secondChar = ( char ) ( secondChar - offset );
554554
}
555555

556556
if( ( firstChar ) != ( secondChar ) )
@@ -1249,6 +1249,7 @@ static uint8_t convertInt32ToAscii( int32_t value,
12491249
uint8_t numOfDigits = 0U;
12501250
uint8_t index = 0U;
12511251
uint8_t isNegative = 0U;
1252+
int32_t bufferIndex;
12521253
char temp = '\0';
12531254

12541255
assert( pBuffer != NULL );
@@ -1263,7 +1264,7 @@ static uint8_t convertInt32ToAscii( int32_t value,
12631264
*pBuffer = '-';
12641265

12651266
/* Convert the value to its absolute representation. */
1266-
absoluteValue = value * -1;
1267+
absoluteValue = value * ( -1 );
12671268
}
12681269

12691270
/* Write the absolute integer value in reverse ASCII representation. */
@@ -1279,11 +1280,12 @@ static uint8_t convertInt32ToAscii( int32_t value,
12791280
for( index = 0U; index < ( numOfDigits / 2U ); index++ )
12801281
{
12811282
temp = pBuffer[ isNegative + index ];
1282-
pBuffer[ isNegative + index ] = pBuffer[ isNegative + numOfDigits - index - 1U ];
1283-
pBuffer[ isNegative + numOfDigits - index - 1U ] = temp;
1283+
bufferIndex = ( int32_t ) isNegative + ( int32_t ) numOfDigits - ( int32_t ) index - 1;
1284+
pBuffer[ isNegative + index ] = pBuffer[ bufferIndex ];
1285+
pBuffer[ bufferIndex ] = temp;
12841286
}
12851287

1286-
return( isNegative + numOfDigits );
1288+
return ( uint8_t ) ( isNegative + numOfDigits );
12871289
}
12881290

12891291
/*-----------------------------------------------------------*/

test/CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,25 @@ if( COV_ANALYSIS )
4444

4545
# Target for Coverity analysis that builds the library.
4646
add_library( coverity_analysis
47-
${HTTP_SOURCES} )
47+
${CMAKE_CURRENT_LIST_DIR}/../source/core_http_client.c )
4848

4949
# Build HTTP library target without custom config dependency.
5050
target_compile_definitions( coverity_analysis PUBLIC HTTP_DO_NOT_USE_CUSTOM_CONFIG=1 )
5151

5252
# HTTP public include path.
5353
target_include_directories( coverity_analysis PUBLIC ${HTTP_INCLUDE_PUBLIC_DIRS} )
5454

55-
# Build HTTP library target without logging
56-
target_compile_options(coverity_analysis PUBLIC -DNDEBUG )
55+
target_compile_options( coverity_analysis PUBLIC
56+
# Build HTTP library target without logging
57+
-DNDEBUG
58+
59+
# GCC compiler option
60+
-Wall
61+
-Wextra
62+
-Wpedantic
63+
-Wconversion
64+
-Werror
65+
)
5766
endif()
5867
# ===================== Clone needed third-party libraries ======================
5968

0 commit comments

Comments
 (0)