-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Undefined behavior adding 1
to nullptr
#2661
Comments
Please provide a self-contained example (preferably in godbolt) that demonstrates the UB. |
@vitaut Here is a minimal reproducer: https://godbolt.org/z/KTYd95o1W When I change |
As an aside, I am using Also note that this is likely a recent regression because the code in question in my code base is pretty old, and I encountered this error in the process of upgrading from 7.3.1 to 8.0.1 today. |
Fixed in 659de77, thanks for reporting.
|
On
master
I am seeing some UB here:which is this line:
when
begin
isnullptr
. But in that case it should be the case thatend
isnullptr
as well, and so we can get around this by only adding1
tobegin
whenbegin != end
, which logically makes sense anyway, since ifbegin == end
thenbegin + 1 < end
will always befalse
anyway. That seems to prevent thebegin + 1
from executing whenbegin == nullptr
. I will send a PR for this.The text was updated successfully, but these errors were encountered: