Bug 16351 - NULL dereference warnings
: NULL dereference warnings
Status: NEW
Product: gcc
Classification: Unclassified
Component: c
: 4.0.0
: P2 enhancement
: ---
Assigned To: Not yet assigned to anyone
:
: diagnostic
:
:
  Show dependency treegraph
 
Reported: 2004-07-03 17:17 UTC by James A. Morrison
Modified: 2007-03-13 16:22 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-18 00:40:59


Attachments
Dereferencing null examples (576 bytes, text/plain)
2004-07-03 17:18 UTC, James A. Morrison
Details
A bad solution for this bug. (1.19 KB, text/plain)
2004-07-03 17:19 UTC, James A. Morrison
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James A. Morrison 2004-07-03 17:17:19 UTC
It'd be really nice if gcc warned about NULL pointer dereferences.
e.g.
 if (foo == NULL && foo->bar)

See the attached test case for more examples.
Comment 1 James A. Morrison 2004-07-03 17:18:30 UTC
Created attachment 6681 [details]
Dereferencing null examples
Comment 2 James A. Morrison 2004-07-03 17:19:24 UTC
Created attachment 6682 [details]
A bad solution for this bug.
Comment 3 Andrew Pinski 2004-07-03 20:16:54 UTC
Confirmed.
Comment 4 James A. Morrison 2004-07-07 06:19:58 UTC
better patch:
http://gcc.gnu.org/ml/gcc-patches/2004-07/msg00423.html
Comment 5 James A. Morrison 2004-10-01 02:16:27 UTC
 dnovillo reviewed this over irc and said it should be done in fold_stmt.  So
far, implementing this in fold_stmt has caused false positives.
Comment 6 Andrew Pinski 2004-12-06 14:19:23 UTC
*** Bug 18854 has been marked as a duplicate of this bug. ***
Comment 7 Johan Walles 2004-12-07 12:04:43 UTC
Bug 18854 deals with *potential* NULL pointer dereferences, while this one
mentions only *confirmed* NULL pointer dereferences, i.e:

1 #include <stdlib.h>
2 int main(int argc, char *argv[]) {
3   volatile char *monkey = (char*)malloc(1234);
4   monkey[0] = '\0';
5   return 0;
6 }

Since malloc() on line 3 can *potentially* return NULL, I'd like a warning on
line 4. 

Phython, would you say potential NULL dereferences are within the scope of this
bug, or should bug 18854 be re-opened for those cases?
Comment 8 James A. Morrison 2004-12-07 16:08:20 UTC
 I'd probably leave them as the same bug for now.  Neither are being fixed for
4.0 so I don't think it's a problem having one bug.
Comment 9 Manuel López-Ibáñez 2007-03-13 16:22:20 UTC
*** Bug 30368 has been marked as a duplicate of this bug. ***