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 return NULL, I'd like a warning on line 4. Likewise, if -Wnonnull is enabled, passing a potential NULL pointer to a function marked with the "nonnull" attribute should give me a warning as well. IMO, all function returning pointers should be considered to potentially return NULL, unless the opposite can be proved. A function attribute saying that some function will never return NULL might be useful, but I'll leave that up to the potential implementer to implement or not. As this warning can potentially trigger in a lot of places in otherwise working code, this warning should be optional and (at least to begin with) default to off. -- Summary: Want warning for potential NULL-dereferences Product: gcc Version: 3.4.4 Status: UNCONFIRMED Severity: enhancement Priority: P2 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: walles at mailblocks dot com CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18854