[Bug c/55746] New: vfprintf behaves differently variable on stack vs const argument.

lbana at hotmail dot com gcc-bugzilla@gcc.gnu.org
Wed Dec 19 23:40:00 GMT 2012


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

             Bug #: 55746
           Summary: vfprintf behaves differently variable on stack vs
                    const argument.
    Classification: Unclassified
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: lbana@hotmail.com


Here is the test code that behaves differently w.r.t vfprintf. In one case it
prints the string where as in other case it crashes.

#include <stdarg.h>
#include <stdio.h>
int main(int argc, const char **argv)
{
    const char *var = "Test VarArg\n";

    asm("nop");
    asm("nop");
    vfprintf(stdout, "TestMe\n", 0);
    asm("nop");
    asm("nop");
    fflush(stdout);
    asm("nop");
    asm("nop");
    vfprintf(stdout, var, 0);
    asm("nop");
    asm("nop");
    fflush(stdout);

    return 0;
}

#gcc -g -o t3 t3.c 
#./t3
TestMe
Segfault


In first case vfprintf is optimized with _fwrite in the second case it uses
_vfprintf and crashes probably in va_copy.

thanks in advance.
lb



More information about the Gcc-bugs mailing list