This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/15685] New: printf("%s\n") optimized to puts also when parameter might be null
- From: "mikko dot tiihonen at hut dot fi" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 27 May 2004 17:05:07 -0000
- Subject: [Bug c/15685] New: printf("%s\n") optimized to puts also when parameter might be null
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The glibc printf %s allows NULL as a parameter while puts() does't so gcc should
not convert the printf to puts unless it is certain that the parameter is not null.
On the other hand if the parameter is certainly null one could call puts("(null)");
See also: bug #15574
Example code:
% cat > bug.i << EOF
extern int printf (__const char *__restrict __format, ...);
int main ()
{
printf ("%s\n", ((void *)0));
return 0;
}
EOF
% gcc bug.i
% ./a.out
(null)
% gcc bug.i -O
% ./a.out
segmentation fault
--
Summary: printf("%s\n") optimized to puts also when parameter
might be null
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mikko dot tiihonen at hut dot fi
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: x86_64-pc-linux-gnu
GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15685