Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out of bounds access in string_view::find #25

Open
1 task done
anopheles63 opened this issue Mar 20, 2022 · 0 comments
Open
1 task done

out of bounds access in string_view::find #25

anopheles63 opened this issue Mar 20, 2022 · 0 comments

Comments

@anopheles63
Copy link

Checklist

  • 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.
[email protected]

Steps to reproduce

Compile and run the following code:

#include <bpstd/string_view.hpp>
#include <iostream>
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant