Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-03-24 15:17:43 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-03-24 15:30:51 +0300
commit70fcecc1f788772ac0ecdbd647583afe995423bb (patch)
treed0ffa9094a372b5c02daf7254bd8813dce87077d
parentbdae647670817f4c09d4c871314f237dde1bfaac (diff)
Fix BLI_strncasestr use with a single character
-rw-r--r--source/blender/blenlib/intern/string.c23
-rw-r--r--tests/gtests/blenlib/BLI_string_test.cc3
2 files changed, 20 insertions, 6 deletions
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index 2f67b0e57a3..f62ffe9e985 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -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);
diff --git a/tests/gtests/blenlib/BLI_string_test.cc b/tests/gtests/blenlib/BLI_string_test.cc
index 5559b8d7af0..17a4b5e82b9 100644
--- a/tests/gtests/blenlib/BLI_string_test.cc
+++ b/tests/gtests/blenlib/BLI_string_test.cc
@@ -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);