# HG changeset patch # User Mike Becker # Date 1767191130 -3600 # Node ID c2d05cf1a0624a58462759bc604b3aa358bf6e47 # Parent 56731bb98508fc4a2b2e26c30e02783ecd131336 fix that Microsoft's _strnicmp crashes when a string is NULL although count == 0 diff -r 56731bb98508 -r c2d05cf1a062 src/string.c --- a/src/string.c Wed Dec 31 15:11:12 2025 +0100 +++ b/src/string.c Wed Dec 31 15:25:30 2025 +0100 @@ -41,7 +41,12 @@ #include #ifdef _WIN32 -#define cx_strcasecmp_impl _strnicmp +static int cx_fixed_strnicmp(const char* s1, const char* s2, size_t count) { + // Microsoft's implementation crashes when count == 0 and either string is NULL + if (count == 0) return 0; + return _strnicmp(s1, s2, count); +} +#define cx_strcasecmp_impl cx_fixed_strnicmp #else #include #define cx_strcasecmp_impl strncasecmp diff -r 56731bb98508 -r c2d05cf1a062 tests/test_string.c --- a/tests/test_string.c Wed Dec 31 15:11:12 2025 +0100 +++ b/tests/test_string.c Wed Dec 31 15:25:30 2025 +0100 @@ -343,7 +343,7 @@ CX_TEST_DO { // the entire string - for (size_t i = 0; i < str.length; i++) { + for (off_t i = 0; i < str.length; i++) { CX_TEST_ASSERT(cx_strat(str, i) == str.ptr[i]); } // the entire string backwards