[Bug c/40097] New: inconsistent printf handling
The following code results in a segmentation fault at Line 7. 1:#include 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
[Bug c/40097] inconsistent printf handling
--- Comment #2 from Andrey dot Martchovsky at gmail dot com 2009-05-11 01:26 --- (In reply to comment #1) > Actually this code is undefined. Using %s with a NULL pointer is undefined so > GCC's behavior is correct. > You are wrong, the GCC behavior is incorrect. Please compile code and run before replying. Lines 4 & 6 behave identically Lines 5 & 7 do not that -- Andrey dot Martchovsky at gmail dot com changed: What|Removed |Added Status|RESOLVED|UNCONFIRMED Resolution|INVALID | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40097
[Bug c++/40098] New: 64bit constants
-- Summary: 64bit constants Product: gcc Version: 4.3.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: Andrey dot Martchovsky at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40098
[Bug c++/40099] New: 64bit constants
The following code produces and...@tiny:~/Documents/Thesis/TIA/pll$ gcc tst.c tst.c:2: warning: integer constant is too large for âlongâ type and...@tiny:~/Documents/Thesis/TIA/pll$ g++ tst.c tst.c:2: error: integer constant is too large for âlongâ type 1:#include 2:long long int tst = 80; 3:int main(){ 4: printf("sizeof(long long int)=%d\n",sizeof(long long int)); 5: printf("tst=%lld\n",tst); 6: return 0; 7:} -- Summary: 64bit constants Product: gcc Version: 4.3.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: Andrey dot Martchovsky at gmail dot com GCC target triplet: g++ (Ubuntu 4.3.3-5ubuntu4) 4.3.3 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40099
[Bug c++/40098] 64bit constants
--- Comment #1 from Andrey dot Martchovsky at gmail dot com 2009-05-11 02:07 --- *** This bug has been marked as a duplicate of 40099 *** -- Andrey dot Martchovsky at gmail dot com changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution||DUPLICATE http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40098
[Bug c++/40099] 64bit constants
--- Comment #1 from Andrey dot Martchovsky at gmail dot com 2009-05-11 02:07 --- *** Bug 40098 has been marked as a duplicate of this bug. *** -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40099
[Bug c++/40099] 64bit constants
--- Comment #3 from Andrey dot Martchovsky at gmail dot com 2009-05-11 18:22 --- (In reply to comment #2) > Why is that a problem? C and C++ are different languages. Compiling with g++ > means you are compiling the C code as C++ (see documentation). > My problem is that the error for 64bit ints in C++ shows up only under the x86 implementation of g++, compiling the same code under x86_64 does not result in any errors. Btw, the documentation for C++ suggests to use either int64_t or long long, for 64bit integers, and with either, I cannot define a constant that is greater than 2^31-1. Therefore this is a bug, as the compiler DOES recognize the declared variable to be 64 bit wide, and DOES all the 64bit arithmetic properly (add,sub,mul,div,mod,shift ...), but DOES NOT recognize the variable to be 64bits in the initial parsing. -- Andrey dot Martchovsky at gmail dot com changed: What|Removed |Added Status|RESOLVED|UNCONFIRMED Resolution|INVALID | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40099
[Bug c++/40099] 64bit constants
--- Comment #5 from Andrey dot Martchovsky at gmail dot com 2009-05-11 19:04 --- (In reply to comment #4) > For C++98 and C90, integer constants can only fit into the long type. You need > to use LL if you want a 64bit integer constant. > Thank you for clarifying this. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40099