The previous calculation took the minimum of the haystack length minus the length of the needle and the offset, which is npos by default and then added the needle length separately. Now, the addition is made to the offset argument, which could overflow and the minimum is no longer correct.
Here's a minimal example that demonstrates the issue:
There seems to be a problem with an old commit that was fixing GCC warnings but I guess a typo was made and now
string::rfind
doesn't work correctly. The commit I found is this: https://github.com/boostorg/container/commit/dad2cb2d02aeccbf2d47eb0e18d73e52b9c51991#diff-aa8e68362c274ac9daa4a59b84b905bfc55747cd6d52c0ec08d3fa1d1350b9beR2442The previous calculation took the minimum of the haystack length minus the length of the needle and the offset, which is
npos
by default and then added the needle length separately. Now, the addition is made to the offset argument, which could overflow and the minimum is no longer correct.Here's a minimal example that demonstrates the issue:
Output is:
The fix should be trivial, just separate the addition of
n
from the minimum function, as it was before.