diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 857c40b79..7abeafdbd 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -516,13 +516,18 @@ SDL_wcsncmp(const wchar_t *str1, const wchar_t *str2, size_t maxlen) #if defined(HAVE_WCSNCMP) return wcsncmp(str1, str2, maxlen); #else - while (*str1 && *str2) { + while (*str1 && *str2 && maxlen) { if (*str1 != *str2) break; ++str1; ++str2; + --maxlen; } - return (int)(*str1 - *str2); + if (!maxlen) { + return 0; + } + return (int) (*str1 - *str2); + #endif /* HAVE_WCSNCMP */ }