https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78586

            Bug ID: 78586
           Summary: Wrong code caused by printf-return-value
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
  Target Milestone: ---

$ cat /tmp/chunk.c
#include <stdio.h>
#include <assert.h>

void
test_no_overflow_long_body (size_t length)
{
  char buf1[3000];
  size_t buf1len = sprintf(buf1, "%lu", (unsigned long)length);

  fprintf (stderr, "buf1: %s\n", buf1);
  fprintf (stderr, "buf1len: %d\n", buf1len);

  assert (buf1len == 4);
}

int main()
{
  test_no_overflow_long_body(1000);
}

$ gcc -O2 /tmp/chunk.c && ./a.out 
buf1: 1000
buf1len: 1
a.out: /tmp/chunk.c:13: test_no_overflow_long_body: Assertion `buf1len == 4'
failed.
Aborted (core dumped)

Reply via email to