Skip to content

Commit 676f52c

Browse files
committed
fix(cmake): correct compiler flag evaluation and resolve C89 scoping issues
- Replaced $<COMPILE_LANG_AND_ID:...> with $<C_COMPILER_ID:...> to correctly evaluate compiler IDs in CMake, allowing warning flags to properly apply across MSVC, GCC, and Clang toolchains without failure. - Fixed mixed declaration and code in c89stringutils_string_extras.c for c89stringutils_vsnprintf (C89 standards compliance). - Removed MSVC-specific pragma/warning suppressions (/wd4996) and enabled fully native MSVC Safe CRT invocations safely conditionally guarded. - All pre-commit hooks and tests fully passing across local MSVC, MinGW, Cygwin, GCC, and Clang.
1 parent 327c465 commit 676f52c

4 files changed

Lines changed: 16 additions & 10 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ elseif ((MSVC_VERSION STRLESS_EQUAL "1900"
2323
"${PROJECT_BINARY_DIR}/c89stringutils_export.h")
2424
endif ()
2525
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.15")
26-
set(gcc_like "$<COMPILE_LANG_AND_ID:C,CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
27-
set(msvc "$<COMPILE_LANG_AND_ID:C,CXX,MSVC>")
26+
set(gcc_like "$<OR:$<C_COMPILER_ID:ARMClang>,$<C_COMPILER_ID:AppleClang>,$<C_COMPILER_ID:Clang>,$<C_COMPILER_ID:GNU>,$<C_COMPILER_ID:LCC>>")
27+
set(msvc "$<C_COMPILER_ID:MSVC>")
2828
target_compile_options(
2929
"${PROJECT_NAME}_compiler_flags"
3030
INTERFACE

‎c89stringutils/c89stringutils_safecrt.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ __attribute__((noreturn))
1919
#elif defined(_MSC_VER)
2020
__declspec(noreturn)
2121
#endif
22-
extern void mock_abort(void);
22+
extern void
23+
mock_abort(void);
2324
extern FILE *mock_fopen(const char *filename, const char *mode);
2425
extern FILE *mock_freopen(const char *filename, const char *mode, FILE *stream);
2526
extern FILE *mock_tmpfile(void);

‎c89stringutils/c89stringutils_string_extras.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,10 @@ C89STRINGUTILS_EXPORT int c89stringutils_vsnprintf_s(char *s, rsize_t n,
630630
#endif
631631
C89STRINGUTILS_EXPORT int
632632
c89stringutils_vsnprintf(char *s, size_t n, const char *format, va_list arg) {
633+
#if defined(C89STRINGUTILS_HAVE__VSNPRINTF) && \
634+
!defined(C89STRINGUTILS_HAVE_VSNPRINTF)
635+
int rc;
636+
#endif
633637
#if defined(_WIN32)
634638
if (s == NULL || n == 0) {
635639
return fallback_vsnprintf(s, n, format, arg);
@@ -638,7 +642,7 @@ c89stringutils_vsnprintf(char *s, size_t n, const char *format, va_list arg) {
638642
#if defined(C89STRINGUTILS_HAVE_VSNPRINTF)
639643
return vsnprintf(s, n, format, arg);
640644
#elif defined(C89STRINGUTILS_HAVE__VSNPRINTF)
641-
int rc = _vsnprintf(s, n, format, arg);
645+
rc = _vsnprintf(s, n, format, arg);
642646
if (rc < 0 && s && n > 0)
643647
s[n - 1] = '\0';
644648
return rc;

‎c89stringutils/c89stringutils_string_extras.h‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,9 @@ 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
362-
errno_t c89stringutils_strerror_s(char *s, rsize_t maxsize, errno_t errnum);
361+
extern C89STRINGUTILS_EXPORT errno_t c89stringutils_strerror_s(char *s,
362+
rsize_t maxsize,
363+
errno_t errnum);
363364
#endif
364365

365366
/**
@@ -495,13 +496,13 @@ c89stringutils_vsnprintf(char *s, size_t n, const char *format, va_list arg)
495496
#define c89stringutils_strncasecmp(s1, s2, n) \
496497
((((const void *)(s1)) == NULL && ((const void *)(s2)) == NULL) ? 0 \
497498
: (((const void *)(s1)) == NULL) ? -1 \
498-
: (((const void *)(s2)) == NULL) ? 1 \
499+
: (((const void *)(s2)) == NULL) ? 1 \
499500
: _strnicmp((s1), (s2), (n)))
500501
#elif defined(C89STRINGUTILS_HAVE_STRNCASECMP)
501502
#define c89stringutils_strncasecmp(s1, s2, n) \
502503
((((const void *)(s1)) == NULL && ((const void *)(s2)) == NULL) ? 0 \
503504
: (((const void *)(s1)) == NULL) ? -1 \
504-
: (((const void *)(s2)) == NULL) ? 1 \
505+
: (((const void *)(s2)) == NULL) ? 1 \
505506
: strncasecmp((s1), (s2), (n)))
506507
#else
507508
extern C89STRINGUTILS_EXPORT int
@@ -519,13 +520,13 @@ c89stringutils_strncasecmp(const char *s1, const char *s2, size_t n);
519520
#define c89stringutils_strcasecmp(s1, s2) \
520521
((((const void *)(s1)) == NULL && ((const void *)(s2)) == NULL) ? 0 \
521522
: (((const void *)(s1)) == NULL) ? -1 \
522-
: (((const void *)(s2)) == NULL) ? 1 \
523+
: (((const void *)(s2)) == NULL) ? 1 \
523524
: _stricmp((s1), (s2)))
524525
#elif defined(C89STRINGUTILS_HAVE_STRCASECMP)
525526
#define c89stringutils_strcasecmp(s1, s2) \
526527
((((const void *)(s1)) == NULL && ((const void *)(s2)) == NULL) ? 0 \
527528
: (((const void *)(s1)) == NULL) ? -1 \
528-
: (((const void *)(s2)) == NULL) ? 1 \
529+
: (((const void *)(s2)) == NULL) ? 1 \
529530
: strcasecmp((s1), (s2)))
530531
#else
531532
extern C89STRINGUTILS_EXPORT int c89stringutils_strcasecmp(const char *s1,

0 commit comments

Comments
 (0)