This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/15685] New: printf("%s\n") optimized to puts also when parameter might be null


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]