Opened 9 years ago

Closed 9 years ago

#7231 closed bug (invalid)

Some issues with handling null-string arguments in printf()

Reported by: mr.Noisy Owned by: axeld
Priority: normal Milestone: R1
Component: System/libroot.so Version: R1/alpha2
Keywords: libroot.so printf null-string Cc:
Blocked By: Blocking:
Has a Patch: no Platform: All

Description

The program

#include <cstdio>

int main()
{
    char* p = 0;
    printf("%s \n", p);
    printf("%s\n", p);
    return 0;
}

will crash on second printf. Haiku hrev40200 GCC4 Hybrid

Change History (3)

comment:1 by mr.Noisy, 9 years ago

Keywords: null-string added; null-char removed

comment:2 by mr.Noisy, 9 years ago

First call of printf() function puts (null) to the stdout.

comment:3 by phoudoin, 9 years ago

Resolution: invalid
Status: newclosed

The culprid is gcc, which optimize printf("%s\n", arg) into puts(arg).

See here:

This can't be fixed in libroot. Sorry. One workaround: use gcc's -fno-builtin-printf option.

Last edited 9 years ago by phoudoin (previous) (diff)
Note: See TracTickets for help on using tickets.