bitwizeshift / bitwizeshift/BackportCpp
out of bounds access in string_view::find
- Dominant language
- C++
- Stars
- 94
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
### Checklist
- [x] I did not find a duplicate of this bug in the Github Issues section.
----------
### Description
I get an exception reporting an out of bound index when running a program using bpstd::string_view which runs fine with a current g++/c++-stdlib. I traced the issue
to an erroneous setup of the upper limit in the for loop present in string_view::find.
Instead of increments = size() - v.size() the code should read increments = size() - v.size() - pos.
I cannot push to the repository, but I can provide a patch.
stefan.schwarzer@gmx.net
### Steps to reproduce
Compile and run the following code:
```c++
#include
#include
using namespace bpstd;
int main() {
string_view n("name.i");
string_view s(".");
string_view::size_type it(0);
while ( it != string_view::npos ) {
std::cout << it << std::endl;
it = n.find(s,it+1);
}
}
```
#### Expected Behavior
I expect the program to find the one missing match at position 4 and then exit. The
output are the two digits 0 and 4 separated by a newline.
#### Actual Behavior
The program reports an out of bounds access in string_view::find
### Extra information
current master branch, tests compile and run without errors.
* Library version: **1.2**
* Operating System: **debian testing**
* Compiler: **g++ 11.2**
Contributor guide
Assessment
This issue has not been assessed yet.