At least glibc's printf, maybe others as well, print (null) in for code like
printf ("%s", NULL) gcc doesn't consider this when optimizing code where the pointer passed for a %s format specifier can be NULL. Example: #include <stdio.h> int main (int argc, char *argv[]) { printf ("%s\n", argc > 1 ? argv[1] : NULL); return 0; } Compiling and running this code (I use gcc 4.0.2) will result in a program which crashes because the printf is transformed into a puts() call and puts() does not allow NULL pointers. There should at least be a mode in which gcc does not perform the transformation if it cannot be sure the pointer is not NULL. The default for Linux and maybe other platforms should be to not perform this optimization if the pointer can be NULL. -- Summary: too agressive printf optimization Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: drepper at redhat dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25609