<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/129498>129498</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang tidy modernize-use-starts-ends-with suggest incorrect fixit if rfind (valid for find also) use not null terminated range
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
belobrov-andrey
</td>
</tr>
</table>
<pre>
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.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8lN-OqzgMxp8m3FitaCgHuOCif06lvd7d61EgBrKTJlVsOtPz9KsAVXtGpyMhqIr9i_35M4rI9A6xFvle5MdEjTz4UDdofRP8daWcDnhLGq9v9cFrBFLni0WR7UQ6XT_S5Up30HpHDMQ6vs52xMG4HhiJ_55_iuwIQsrHP0JKke1nFBArNu1Mwc9LeJBUCOomskM7qCDkAaTIfk7cw6DCLr6c0cV-Zry1ivgen_0Uskw_90chKyEPj5P-FFXJGFUcRbYHIU9CnmDmGwLnGdxoLTCGs3GKUS-VN95b6Pzo9FTHo7916IzTQpa_FbvWipWQ5VwQpPH2ewCZX3gPqCIzYtNFqifJRbo7WBVFNvoGNPY9EhOwh3ZQrkdYZvBheICplvjuC-R19cQqML3F7G97qJ7k-mcwFNX6dw9kXItf5vRax6eK9iOD4XvsVVmjF1jrR8egQj-e0TH4bukqntk7H1CvZ1n-YrDevxNY844RRoMfrYYGAQ0PGMB56MwnKAZlLZhuYZsOLooIJ6WW8Z3mxwF8mHIWFquIduxBtXPyfL8qO95X5Kmrl8KKYv-dP15aozjO0n85Z5pAG5f1w1gLbcAo8WKFt6vBj9kPrQ8BW4ZIjEpOWwbK6Tl5afLDh_d7qL2tE11nusoqlWC9KbZpVcltJZOhLlRbYL4tq0KqYlMWEttS53lTVrkqi3KTmFqmMk-zNEurdJPJddH92G7LrOrSIi-yQoptimdl7Nra63ntQ58YohHrjay2VZlY1aCl6UMlZRtdH78e-TEJdUxYNWNPYptaQ0wPBBu2WD8tydlrDM78wtVIuJoHsUKnaTWJsuwQGHeXpzOfZrLF7DQhy9mQ3WQGp0FZ8nFNR8I_eRtC3MRkDLYemC8UjTGtSm94GJt1689CnmLBy2N1Cf4_bFnI0yQACXlaNLjW8v8AAAD__4z82TY">