public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/15685] New: printf("%s\n") optimized to puts also when parameter might be null
@ 2004-05-28  3:19 mikko dot tiihonen at hut dot fi
  2004-05-28  3:31 ` [Bug c/15685] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 6+ messages in thread
From: mikko dot tiihonen at hut dot fi @ 2004-05-28  3:19 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-10-19 14:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-15685-8634@http.gcc.gnu.org/bugzilla/>
2005-12-30 23:07 ` [Bug c/15685] printf("%s\n") optimized to puts also when parameter might be null pinskia at gcc dot gnu dot org
2005-12-30 23:49 ` pinskia at gcc dot gnu dot org
2007-10-01  6:45 ` mathias dot hasselmann at gmx dot de
2007-10-01  9:12 ` manu at gcc dot gnu dot org
2007-10-19 14:47 ` manu at gcc dot gnu dot org
2004-05-28  3:19 [Bug c/15685] New: " mikko dot tiihonen at hut dot fi
2004-05-28  3:31 ` [Bug c/15685] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).