diff options
author | Ryan C. Gordon <icculus@icculus.org> | 2020-07-24 22:24:03 -0400 |
---|---|---|
committer | Ryan C. Gordon <icculus@icculus.org> | 2020-07-24 22:24:03 -0400 |
commit | a4f2e3a82c376cc792bcd9c708c875b47af34b25 (patch) | |
tree | c50b0c2dca01c0a45a7b3d597ed7ec29b250a528 /src/stdlib | |
parent | eadb4a038d04ff9768772f4175cc739c464d1131 (diff) | |
download | sdl-a4f2e3a82c376cc792bcd9c708c875b47af34b25.tar.gz |
stdlib: Corrected implementation of SDL_wcsncmp.
It was a copy/paste of SDL_strcmp, apparently, not SDL_strncmp, so it ignored
the maxlen parameter.
Thanks to Jack Powell for pointing this out!
Diffstat (limited to 'src/stdlib')
-rw-r--r-- | src/stdlib/SDL_string.c | 9 |
1 files changed, 7 insertions, 2 deletions
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 */ } |