From d9480ace0c6a46510eae68dcf5f388a5eb47e51c Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 13 Mar 2024 16:11:34 -0400 Subject: [PATCH] Fix strict warnings (#65) * Fix strict warnings * Remove suffixing backslash --- CMakeLists.txt | 6 +++--- cvector.h | 2 +- unit-tests.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a69213b..b9b3b39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ PUBLIC ) set_target_properties(c-vector-example PROPERTIES C_STANDARD 90) -target_compile_options(c-vector-example PUBLIC -Wall -Wextra) +target_compile_options(c-vector-example PUBLIC -Wall -Werror -Wextra) # ---------------------------- @@ -35,7 +35,7 @@ add_executable(test-c-vector add_test(NAME test-c-vector COMMAND test-c-vector) set_target_properties(test-c-vector PROPERTIES C_STANDARD 90) -target_compile_options(test-c-vector PUBLIC -Wall -Wextra) +target_compile_options(test-c-vector PUBLIC -Wall -Werror -Wextra) add_test(test_build "${CMAKE_COMMAND}" @@ -69,7 +69,7 @@ add_executable(unit-tests add_test(NAME unit-tests COMMAND $) set_target_properties(unit-tests PROPERTIES C_STANDARD 90) -target_compile_options(unit-tests PUBLIC -Wall -Wextra) +target_compile_options(unit-tests PUBLIC -Wall -Werror -Wextra) add_test(unit_test_build "${CMAKE_COMMAND}" diff --git a/cvector.h b/cvector.h index ea8e0f9..eec179e 100644 --- a/cvector.h +++ b/cvector.h @@ -419,7 +419,7 @@ typedef struct cvector_metadata_t { * @return the element at the specified position in the vector. */ #define cvector_at(vec, n) \ - ((vec) ? ((n < 0 || n >= cvector_size(vec)) ? NULL : &(vec)[n]) : NULL) + ((vec) ? (((int)(n) < 0 || (size_t)(n) >= cvector_size(vec)) ? NULL : &(vec)[n]) : NULL) /** * @brief cvector_front - returns a reference to the first element in the vector. Unlike member cvector_begin, which returns an iterator to this same element, this function returns a direct reference. diff --git a/unit-tests.c b/unit-tests.c index b4cacbe..b4c74da 100644 --- a/unit-tests.c +++ b/unit-tests.c @@ -54,7 +54,7 @@ UTEST(test, vector_at) { if (v) { int i = 0; - for (; i < cvector_size(v); i++) { + for (; i < (int)cvector_size(v); i++) { ASSERT_TRUE(*cvector_at(v, i) == i); } }