diff options
author | Max Kellermann <max@duempel.org> | 2015-11-06 09:24:18 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2015-11-06 09:24:18 +0100 |
commit | 42f5ecd4a116c96d30bf407859dadaa9a053ea39 (patch) | |
tree | 644ee945bda37afde922b9a3306fd19c3af23200 | |
parent | 733989a284d2f7cce37634b12afad72cc019f659 (diff) | |
download | mpd-42f5ecd4a116c96d30bf407859dadaa9a053ea39.tar.gz mpd-42f5ecd4a116c96d30bf407859dadaa9a053ea39.tar.xz mpd-42f5ecd4a116c96d30bf407859dadaa9a053ea39.zip |
util/StringCompare: use strncmp() instead of memcmp() in StringStartsWith()
Some optimized implementations of memcmp() may not start from the
beginning of the string, and may thus segfault.
Diffstat (limited to '')
-rw-r--r-- | src/util/StringCompare.cxx | 4 | ||||
-rw-r--r-- | src/util/WStringCompare.cxx | 3 |
2 files changed, 4 insertions, 3 deletions
diff --git a/src/util/StringCompare.cxx b/src/util/StringCompare.cxx index a7e505d12..fbd8e1d6d 100644 --- a/src/util/StringCompare.cxx +++ b/src/util/StringCompare.cxx @@ -36,8 +36,8 @@ bool StringStartsWith(const char *haystack, const char *needle) { - const size_t length = strlen(needle); - return memcmp(haystack, needle, length) == 0; + const size_t length = StringLength(needle); + return StringIsEqual(haystack, needle, length); } bool diff --git a/src/util/WStringCompare.cxx b/src/util/WStringCompare.cxx index 77c3a8629..723f7e47b 100644 --- a/src/util/WStringCompare.cxx +++ b/src/util/WStringCompare.cxx @@ -26,7 +26,8 @@ bool StringStartsWith(const wchar_t *haystack, const wchar_t *needle) { - return memcmp(haystack, needle, StringLength(needle) * sizeof(needle[0])) == 0; + const size_t length = StringLength(needle); + return StringIsEqual(haystack, needle, length); } bool |