public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/37765]  New: Printf of typed null pointer causes a run-time error
@ 2008-10-08  4:33 hosoda-t at palette dot plala dot or dot jp
  2008-10-08  7:38 ` [Bug c++/37765] " schwab at suse dot de
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: hosoda-t at palette dot plala dot or dot jp @ 2008-10-08  4:33 UTC (permalink / raw)
  To: gcc-bugs

#include <cstdio>
int main()
{
    printf("%s\n", (char*)0); // run-time error for g++ 4.3.2,
}                             // while ok for g++ 3.4.4

run-time error:
       10 [main] a 1808 _cygtls::handle_exceptions: Error while dumping state 
(probably corrupted stack) Segmentation fault (core dumped)

expexted behavior:print nothing or (null)
workaround: use cout
comment:
       Many people still prefer printf to cout. The disabled function make
printf almost useless.


-- 
           Summary: Printf of typed null pointer causes a run-time error
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hosoda-t at palette dot plala dot or dot jp
  GCC host triplet: Microsoft Windows XP
GCC target triplet: i686-pc-cygwin


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37765


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

* [Bug c++/37765] Printf of typed null pointer causes a run-time error
  2008-10-08  4:33 [Bug c++/37765] New: Printf of typed null pointer causes a run-time error hosoda-t at palette dot plala dot or dot jp
@ 2008-10-08  7:38 ` schwab at suse dot de
  2008-10-08 23:03 ` hosoda-t at palette dot plala dot or dot jp
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: schwab at suse dot de @ 2008-10-08  7:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from schwab at suse dot de  2008-10-08 07:36 -------
"%s" requires a pointer to a string, which (char*)0 isn't.


-- 

schwab at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37765


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

* [Bug c++/37765] Printf of typed null pointer causes a run-time error
  2008-10-08  4:33 [Bug c++/37765] New: Printf of typed null pointer causes a run-time error hosoda-t at palette dot plala dot or dot jp
  2008-10-08  7:38 ` [Bug c++/37765] " schwab at suse dot de
@ 2008-10-08 23:03 ` hosoda-t at palette dot plala dot or dot jp
  2008-10-08 23:07 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: hosoda-t at palette dot plala dot or dot jp @ 2008-10-08 23:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from hosoda-t at palette dot plala dot or dot jp  2008-10-08 23:02 -------
(In reply to comment #1)
> "%s" requires a pointer to a string, which (char*)0 isn't.

"%s" is a c-style string.
try the code below, and please notice that the code works well on g++ 3.4.4 and
also on Microsoft Visual C++ 2005 without a run-time error.

#include <cstdio>
int main()
{
    const char* p = "This is a c-syle string.";
    printf("%s\n", p);
    char* q = 0;
    printf("%s\n", q);
}


-- 

hosoda-t at palette dot plala dot or dot jp changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37765


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

* [Bug c++/37765] Printf of typed null pointer causes a run-time error
  2008-10-08  4:33 [Bug c++/37765] New: Printf of typed null pointer causes a run-time error hosoda-t at palette dot plala dot or dot jp
  2008-10-08  7:38 ` [Bug c++/37765] " schwab at suse dot de
  2008-10-08 23:03 ` hosoda-t at palette dot plala dot or dot jp
@ 2008-10-08 23:07 ` pinskia at gcc dot gnu dot org
  2008-10-09  2:42 ` hosoda-t at palette dot plala dot or dot jp
  2008-10-09  8:20 ` paolo dot carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-10-08 23:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2008-10-08 23:05 -------
printf ("%s\n", NULL);
is undefined.  So GCC is optimizing the printf in this case to puts which
creates smaller and faster code.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37765


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

* [Bug c++/37765] Printf of typed null pointer causes a run-time error
  2008-10-08  4:33 [Bug c++/37765] New: Printf of typed null pointer causes a run-time error hosoda-t at palette dot plala dot or dot jp
                   ` (2 preceding siblings ...)
  2008-10-08 23:07 ` pinskia at gcc dot gnu dot org
@ 2008-10-09  2:42 ` hosoda-t at palette dot plala dot or dot jp
  2008-10-09  8:20 ` paolo dot carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: hosoda-t at palette dot plala dot or dot jp @ 2008-10-09  2:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from hosoda-t at palette dot plala dot or dot jp  2008-10-09 02:40 -------
Thank you for your time. I am sure that you are right, because the Null pointer
does not point to a string which must have the terminator '\0' at the end.

However, please kindly adivise me if the folloing code also work on a undefined
behavior or not.

cout << (char*)0;




-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37765


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

* [Bug c++/37765] Printf of typed null pointer causes a run-time error
  2008-10-08  4:33 [Bug c++/37765] New: Printf of typed null pointer causes a run-time error hosoda-t at palette dot plala dot or dot jp
                   ` (3 preceding siblings ...)
  2008-10-09  2:42 ` hosoda-t at palette dot plala dot or dot jp
@ 2008-10-09  8:20 ` paolo dot carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo dot carlini at oracle dot com @ 2008-10-09  8:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from paolo dot carlini at oracle dot com  2008-10-09 08:19 -------
Yes, all those inserters, per 27.6.2.5.4/3 Require a non-null s.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37765


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

end of thread, other threads:[~2008-10-09  8:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-08  4:33 [Bug c++/37765] New: Printf of typed null pointer causes a run-time error hosoda-t at palette dot plala dot or dot jp
2008-10-08  7:38 ` [Bug c++/37765] " schwab at suse dot de
2008-10-08 23:03 ` hosoda-t at palette dot plala dot or dot jp
2008-10-08 23:07 ` pinskia at gcc dot gnu dot org
2008-10-09  2:42 ` hosoda-t at palette dot plala dot or dot jp
2008-10-09  8:20 ` paolo dot carlini at oracle dot com

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).