boostorg / test

The reference C++ unit testing framework (TDD, xUnit, C++03/11/14/17)
http://boost.org/libs/test
Boost Software License 1.0
183 stars 140 forks source link

Fix undefined behavior in `basic_cstring::rfind` #360

Closed Flamefire closed 1 year ago

Flamefire commented 2 years ago

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