[Bug c/40097] New: inconsistent printf handling
Andrey dot Martchovsky at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon May 11 00:55:00 GMT 2009
The following code results in a segmentation fault at Line 7.
1:#include <stdio.h>
2:int main(){
3: const char *tmp = NULL;
4: printf("%s \n",NULL);
5: printf("%s\n",NULL);
6: printf("%s \n",tmp);
7: printf("%s\n",tmp);
8: return 1;
9:}
I've traced the bug to the code optimization in
/usr/src/gcc-4.3/gcc-4.3.3/gcc/builtins.c
fold_builtin_printf()
the printf() is replaced with puts(), which has no null handling
The alternate solution would be to add a NULL check to puts() or putc() in
libc.
This inconsistency is a major setback when porting code from Windows to Linux
as MCVC++ compiles the above code correctly and GCC does not.
--
Summary: inconsistent printf handling
Product: gcc
Version: 4.3.3
Status: UNCONFIRMED
Severity: blocker
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Andrey dot Martchovsky at gmail dot com
GCC target triplet: gcc (Ubuntu 4.3.3-5ubuntu4) 4.3.3
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40097
More information about the Gcc-bugs
mailing list