diff options
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Support/StringRef.cpp | 2 | ||||
| -rw-r--r-- | llvm/unittests/ADT/StringRefTest.cpp | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp index d7fa99dbde2..393504cf01b 100644 --- a/llvm/lib/Support/StringRef.cpp +++ b/llvm/lib/Support/StringRef.cpp @@ -372,7 +372,7 @@ void StringRef::split(SmallVectorImpl<StringRef> &A, char Separator, size_t StringRef::count(StringRef Str) const { size_t Count = 0; size_t N = Str.size(); - if (N > Length) + if (!N || N > Length) return 0; for (size_t i = 0, e = Length - N + 1; i < e;) { if (substr(i, N).equals(Str)) { diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp index cbb2a30ff17..9cb24bfdb4d 100644 --- a/llvm/unittests/ADT/StringRefTest.cpp +++ b/llvm/unittests/ADT/StringRefTest.cpp @@ -509,6 +509,7 @@ TEST(StringRefTest, Count) { EXPECT_EQ(1U, Str.count("hello")); EXPECT_EQ(1U, Str.count("ello")); EXPECT_EQ(0U, Str.count("zz")); + EXPECT_EQ(0U, Str.count("")); StringRef OverlappingAbba("abbabba"); EXPECT_EQ(1U, OverlappingAbba.count("abba")); |

