| Issue |
129498
|
| Summary |
Clang tidy modernize-use-starts-ends-with suggest incorrect fixit if rfind (valid for find also) use not null terminated range
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
belobrov-andrey
|
Code sample:
```
const std::string testString = "testString";
static constexpr std::array<char, 2> testCharArray = {static_cast<char>(0xBD),
static_cast<char>(0x92)}; // Array is not null terminated
bool found = testString.rfind(testCharArray.data(), 0, testCharArray.size()) == 0;
```
Clang tidy suggests to change string with rfind to
```
bool found = testString.starts_with(testCharArray.data()); // This is UB since testCharArray is not null terminated
```
But it is not valid since count argument of rfind is ignored.
It looks like it should be either no fix at all if count if passed to rfind/find, or fix should take into account count value:
```
testString.starts_with({testCharArray.data(), testCharArray.size()});
```
This code will created string_view with correct size of array and code should work correctly.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs