GCC Bugzilla – Bug 16351
NULL dereference warnings
Last modified: 2007-03-13 16:22:20 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.
Created attachment 6681 [details] Dereferencing null examples
Created attachment 6682 [details] A bad solution for this bug.
Confirmed.
better patch: http://gcc.gnu.org/ml/gcc-patches/2004-07/msg00423.html
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.
*** Bug 18854 has been marked as a duplicate of this bug. ***
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?
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.
*** Bug 30368 has been marked as a duplicate of this bug. ***