Skip to content

Commit 45d83d1

Browse files
committed
fix(ci): resolve strict compiler warnings and cmake mutation
- Fix FetchContent_MakeAvailable to avoid mutating greatest.h in local source dir. - Fix -Wmissing-prototypes for real_main. - Fix -Wformat mismatch in fscanf_s mock. - Fix -Wunused-function for test mocks. - Ensure #include <stdarg.h> is clang-format guarded in test_amalg.c.
1 parent 41f61e3 commit 45d83d1

7 files changed

Lines changed: 22 additions & 39 deletions

File tree

‎c89stringutils/c89stringutils_safecrt.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,13 @@
1313
#include <string.h>
1414
/* clang-format on */
1515

16-
#if defined(_MSC_VER)
17-
#endif
18-
1916
#ifdef C89STRINGUTILS_TEST_MOCKS
2017
#if defined(__GNUC__) || defined(__clang__)
2118
__attribute__((noreturn))
2219
#elif defined(_MSC_VER)
2320
__declspec(noreturn)
2421
#endif
25-
extern void
26-
mock_abort(void);
22+
extern void mock_abort(void);
2723
extern FILE *mock_fopen(const char *filename, const char *mode);
2824
extern FILE *mock_freopen(const char *filename, const char *mode, FILE *stream);
2925
extern FILE *mock_tmpfile(void);
@@ -44,8 +40,6 @@ extern int mock_strcat_s(char *dest, size_t destsz, const char *src);
4440
#define fopen mock_fopen
4541
#define freopen mock_freopen
4642
#define tmpfile mock_tmpfile
47-
extern int mock_tmpfile_s(FILE **pFile);
48-
#define tmpfile_s mock_tmpfile_s
4943
#endif
5044

5145
/**

‎c89stringutils/c89stringutils_string_extras.h‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,8 @@ typedef size_t rsize_t;
358358
#if defined(C89STRINGUTILS_HAVE_STRERROR_S)
359359
#define c89stringutils_strerror_s strerror_s
360360
#else
361-
extern C89STRINGUTILS_EXPORT errno_t c89stringutils_strerror_s(char *s,
362-
rsize_t maxsize,
363-
errno_t errnum);
361+
extern C89STRINGUTILS_EXPORT
362+
errno_t c89stringutils_strerror_s(char *s, rsize_t maxsize, errno_t errnum);
364363
#endif
365364

366365
/**
@@ -496,13 +495,13 @@ c89stringutils_vsnprintf(char *s, size_t n, const char *format, va_list arg)
496495
#define c89stringutils_strncasecmp(s1, s2, n) \
497496
((((const void *)(s1)) == NULL && ((const void *)(s2)) == NULL) ? 0 \
498497
: (((const void *)(s1)) == NULL) ? -1 \
499-
: (((const void *)(s2)) == NULL) ? 1 \
498+
: (((const void *)(s2)) == NULL) ? 1 \
500499
: _strnicmp((s1), (s2), (n)))
501500
#elif defined(C89STRINGUTILS_HAVE_STRNCASECMP)
502501
#define c89stringutils_strncasecmp(s1, s2, n) \
503502
((((const void *)(s1)) == NULL && ((const void *)(s2)) == NULL) ? 0 \
504503
: (((const void *)(s1)) == NULL) ? -1 \
505-
: (((const void *)(s2)) == NULL) ? 1 \
504+
: (((const void *)(s2)) == NULL) ? 1 \
506505
: strncasecmp((s1), (s2), (n)))
507506
#else
508507
extern C89STRINGUTILS_EXPORT int
@@ -520,13 +519,13 @@ c89stringutils_strncasecmp(const char *s1, const char *s2, size_t n);
520519
#define c89stringutils_strcasecmp(s1, s2) \
521520
((((const void *)(s1)) == NULL && ((const void *)(s2)) == NULL) ? 0 \
522521
: (((const void *)(s1)) == NULL) ? -1 \
523-
: (((const void *)(s2)) == NULL) ? 1 \
522+
: (((const void *)(s2)) == NULL) ? 1 \
524523
: _stricmp((s1), (s2)))
525524
#elif defined(C89STRINGUTILS_HAVE_STRCASECMP)
526525
#define c89stringutils_strcasecmp(s1, s2) \
527526
((((const void *)(s1)) == NULL && ((const void *)(s2)) == NULL) ? 0 \
528527
: (((const void *)(s1)) == NULL) ? -1 \
529-
: (((const void *)(s2)) == NULL) ? 1 \
528+
: (((const void *)(s2)) == NULL) ? 1 \
530529
: strcasecmp((s1), (s2)))
531530
#else
532531
extern C89STRINGUTILS_EXPORT int c89stringutils_strcasecmp(const char *s1,

‎c89stringutils/tests/CMakeLists.txt‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,19 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS")
1616
greatest
1717
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../greatest"
1818
)
19-
FetchContent_MakeAvailable(greatest)
20-
if (MSVC)
21-
file(READ "${greatest_SOURCE_DIR}/greatest.h" _greatest_content)
22-
string(REPLACE "while (0)" "while (0,0)" _greatest_content "${_greatest_content}")
23-
file(WRITE "${greatest_SOURCE_DIR}/greatest.h" "${_greatest_content}")
24-
endif()
25-
file(COPY "${greatest_SOURCE_DIR}/greatest.h" DESTINATION "${DOWNLOAD_DIR}")
2619
else()
2720
FetchContent_Declare(
2821
greatest
2922
URL "https://raw.githubusercontent.com/SamuelMarks/greatest/master/greatest.h"
3023
DOWNLOAD_NO_EXTRACT TRUE
3124
)
32-
FetchContent_MakeAvailable(greatest)
33-
if (MSVC)
34-
file(READ "${greatest_SOURCE_DIR}/greatest.h" _greatest_content)
35-
string(REPLACE "while (0)" "while (0,0)" _greatest_content "${_greatest_content}")
36-
file(WRITE "${greatest_SOURCE_DIR}/greatest.h" "${_greatest_content}")
37-
endif()
38-
file(COPY "${greatest_SOURCE_DIR}/greatest.h" DESTINATION "${DOWNLOAD_DIR}")
25+
endif()
26+
FetchContent_MakeAvailable(greatest)
27+
file(COPY "${greatest_SOURCE_DIR}/greatest.h" DESTINATION "${DOWNLOAD_DIR}")
28+
if (MSVC)
29+
file(READ "${DOWNLOAD_DIR}/greatest.h" _greatest_content)
30+
string(REPLACE "while (0)" "while (0,0)" _greatest_content "${_greatest_content}")
31+
file(WRITE "${DOWNLOAD_DIR}/greatest.h" "${_greatest_content}")
3932
endif()
4033
endif (NOT CMAKE_SYSTEM_NAME STREQUAL "SunOS")
4134

@@ -51,7 +44,7 @@ source_group("Source Files" FILES "${Source_Files}")
5144

5245
add_executable("${EXEC_NAME}" "${Header_Files}" "${Source_Files}")
5346

54-
target_compile_definitions("${EXEC_NAME}" PRIVATE C89STRINGUTILS_TEST_MOCKS C89STRINGUTILS_STATIC_DEFINE DEBUG _CRT_SECURE_NO_WARNINGS)
47+
target_compile_definitions("${EXEC_NAME}" PRIVATE C89STRINGUTILS_TEST_MOCKS C89STRINGUTILS_STATIC_DEFINE DEBUG)
5548

5649
if (NOT CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom")
5750
target_link_libraries("${EXEC_NAME}" PRIVATE "${PROJECT_NAME}_compiler_flags")

‎c89stringutils/tests/test.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ int mock_strerror_r(int errnum, char *buf, size_t buflen);
5555
FILE *mock_fopen(const char *filename, const char *mode);
5656
FILE *mock_freopen(const char *filename, const char *mode, FILE *stream);
5757
FILE *mock_tmpfile(void);
58+
int real_main(int argc, char **argv);
5859

5960
#if defined(C89STRINGUTILS_HAVE_STRNCPY_S)
6061
int mock_strncpy_s(char *dest, size_t destsz, const char *src, size_t count);
@@ -403,14 +404,6 @@ FILE *mock_freopen(const char *filename, const char *mode, FILE *stream) {
403404
#endif
404405
}
405406

406-
int mock_tmpfile_s(FILE **pFile) {
407-
if (g_mock_fopen_fail) {
408-
*pFile = NULL;
409-
return 12;
410-
}
411-
return tmpfile_s(pFile);
412-
}
413-
414407
FILE *mock_tmpfile(void) {
415408

416409
if (g_mock_fopen_fail) {

‎c89stringutils/tests/test_amalg.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include "c89stringutils_amalgamation.h"
77
#include <stdio.h>
88
#include <stdlib.h>
9-
/* clang-format on */
109
#include <stdarg.h>
10+
/* clang-format on */
1111

1212
int g_mock_printf_fail = 0;
1313
int mock_printf(const char *format, ...) {

‎c89stringutils/tests/test_safecrt.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ static void mock_reset_safecrt_cb(void *data) {
366366
g_mock_strcat_s_countdown = -1;
367367
}
368368

369+
#if defined(C89STRINGUTILS_FORCE_FALLBACKS)
369370
TEST test_mock_sscanf_s_failures(void) {
370371
c89stringutils_set_constraint_handler_s(c89stringutils_ignore_handler_s);
371372

@@ -410,14 +411,15 @@ TEST test_mock_fscanf_s_failures(void) {
410411

411412
rewind(f);
412413
g_mock_ungetc_countdown = 1;
413-
rc = c89stringutils_fscanf_s(f, "12%c", &val);
414+
rc = c89stringutils_fscanf_s(f, "12%d", &val);
414415

415416
fclose(f);
416417
remove("test_fscanf_mock.txt");
417418

418419
c89stringutils_set_constraint_handler_s(test_handler);
419420
PASS();
420421
}
422+
#endif
421423

422424
SUITE(safecrt_suite) {
423425
SET_SETUP(mock_reset_safecrt_cb, NULL);

‎c89stringutils/tests/test_string_extras.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ static void mock_reset_cb(void *data) {
831831
g_mock_fprintf_countdown = -1;
832832
}
833833

834+
#if defined(C89STRINGUTILS_FORCE_FALLBACKS)
834835
TEST x_mock_strncpy_s_failure(void) {
835836
#if defined(C89STRINGUTILS_HAVE_STRNCPY_S)
836837
char buf[256];
@@ -894,6 +895,7 @@ TEST x_mock_jasprintf_memcpy_failure(void) {
894895
#endif
895896
PASS();
896897
}
898+
#endif
897899

898900
SUITE(strnstr_suite) {
899901
SET_SETUP(mock_reset_cb, NULL);

0 commit comments

Comments
 (0)