[llvm-bugs] [Bug 44072] New: StringRef::count(StringRef) doesn't behave as documented

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 20 01:47:31 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=44072

            Bug ID: 44072
           Summary: StringRef::count(StringRef) doesn't behave as
                    documented
           Product: new-bugs
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: benno at bensge.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

The StringRef::count(StringRef) documentation reads as follows:
Return the number of non-overlapped occurrences of \arg Str in the string.
However, the implementation of this method actually counts overlapping
occurrences as well. 

Minimum example:
`StringRef("abbabba").count("abba")` returns 2, when it should return 1.

There are very few usages of this API in LLVM. I could only find one usage of
this API where the bug actually makes a difference. All other usages used a
search string with length one, the bug doesn't affect this special case.

There are no tests to ensure the correct overlapping-occurrence behavior of
this function.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191120/26258071/attachment.html>


More information about the llvm-bugs mailing list