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

Fix undefined behavior in basic_cstring::rfind #360

Merged
merged 4 commits into from
Feb 6, 2023

Conversation

Flamefire
Copy link
Contributor

Getting the pointer to 1-before an array is undefined behavior, i.e. begin() - 1 is not allowed.
So modify rfind to loop until the front and do a final comparison with begin()/first afterwards before returning npos.
Use a better-suited for-loop and modify find to look as similar as possible so the difference is easy to spot.

Fixes #357

Flamefire and others added 4 commits October 10, 2022 13:37
This will now create a static `CharT[]` array and return that by reference as-if `"foo"` was used instead of `LITERAL("foo")`
Getting the pointer to 1-before an array is undefined behavior, i.e. `begin() - 1` is not allowed.
So modify `rfind` to loop until the front and do a final comparison with `begin()/first` afterwards before returning `npos`.
Use a better-suited for-loop and modify `find` to look as similar as possible so the difference is easy to spot.

Fixes boostorg#357
@mborland mborland merged commit 418581f into boostorg:develop Feb 6, 2023
@Flamefire Flamefire deleted the find_fix branch February 6, 2023 17:30
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

Successfully merging this pull request may close these issues.

Undefined behavior in rfind
2 participants