-
Notifications
You must be signed in to change notification settings - Fork 274
NULL compares equal to 0 #4526
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
NULL compares equal to 0 #4526
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: 15bf786).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/108192432
If |
(Very academic question; I am yet to spot a system in which NULL isn't a zero bit pattern). |
See http://c-faq.com/null/machexamp.html for the discussion of NULL-is-not-zero. But, yes, this remains academic. |
Hmm, indeed, we should probably just refrain from simplifying in that case. Let me fix this. |
15bf786
to
7562a99
Compare
Done. |
As a side note: a still-current scenario is that the address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: 7562a99).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/108214328
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test exercising the !null_is_zero
path?
regression/cbmc/union13/main.c
Outdated
int main() | ||
{ | ||
union { | ||
unsigned long long i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK unsigned long
is the type guaranteed to have same size as a pointer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not on Windows/LLP64... (and also it would be ok for the integer type to be larger than the pointer type in this union, but not the other way around)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gah, so it isn't, Though perhaps intptr_t
is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
7562a99
to
0201b0a
Compare
Test added! |
When comparing constants, we just compared their string representations. This fails when one side of the (in)equality was NULL while the other side was 0, which is wrong when config.ansi_c.NULL_is_zero is set. Thus actually test both sides for being zero in this configuration.
0201b0a
to
8f68057
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
Passed Diffblue compatibility checks (cbmc commit: 8f68057).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/108223887
When comparing constants, we just compared their string representations.
This fails when one side of the (in)equality was NULL while the other
side was 0, which is wrong when config.ansi_c.NULL_is_zero is set. Thus
actually test both sides for being zero in this configuration.