Fix BLI_strncasestr use with a single character

This commit is contained in:
Campbell Barton 2016-03-24 23:17:43 +11:00
parent bdae647670
commit 70fcecc1f7
2 changed files with 20 additions and 6 deletions

@ -534,13 +534,24 @@ char *BLI_strncasestr(const char *s, const char *find, size_t len)
if ((c = *find++) != 0) {
c = tolower(c);
do {
if (len > 1) {
do {
if ((sc = *s++) == 0)
return (NULL);
sc = tolower(sc);
} while (sc != c);
} while (BLI_strncasecmp(s, find, len - 1) != 0);
do {
if ((sc = *s++) == 0)
return NULL;
sc = tolower(sc);
} while (sc != c);
} while (BLI_strncasecmp(s, find, len - 1) != 0);
}
else {
{
do {
if ((sc = *s++) == 0)
return NULL;
sc = tolower(sc);
} while (sc != c);
}
}
s--;
}
return ((char *)s);

@ -451,6 +451,9 @@ TEST(string, StringStrncasestr)
res = BLI_strncasestr(str_test0, "", 0);
EXPECT_EQ(str_test0, res);
res = BLI_strncasestr(str_test0, " ", 1);
EXPECT_EQ(str_test0 + 6, res);
res = BLI_strncasestr(str_test0, "her", 3);
EXPECT_EQ(str_test0 + 7, res);