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.
This commit is contained in:
Max Kellermann 2015-11-06 09:24:18 +01:00
parent 733989a284
commit 42f5ecd4a1
2 changed files with 4 additions and 3 deletions

View File

@ -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

View File

@ -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