Fix BLI_strncasestr use with a single character
This commit is contained in:
parent
bdae647670
commit
70fcecc1f7
@ -534,13 +534,24 @@ char *BLI_strncasestr(const char *s, const char *find, size_t len)
|
||||
|
||||
if ((c = *find++) != 0) {
|
||||
c = tolower(c);
|
||||
if (len > 1) {
|
||||
do {
|
||||
do {
|
||||
if ((sc = *s++) == 0)
|
||||
return (NULL);
|
||||
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user