(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
torture/
pr47917.c
       1  /* { dg-do run } */
       2  /* { dg-options "-std=c99" } */
       3  /* { dg-options "-std=gnu99" { target *-*-hpux* } } */
       4  /* { dg-additional-options "-D__USE_MINGW_ANSI_STDIO=1" { target *-*-mingw* } } */
       5  /* { dg-xfail-run-if "non-conforming C99 snprintf" { *-*-hpux11.[012]* } } */
       6  
       7  /* PR middle-end/47917 */
       8  
       9  #include <stdio.h>
      10  extern int memcmp (const void *, const void *, __SIZE_TYPE__);
      11  extern void abort (void);
      12  
      13  char buf1[6], buf2[6], buf3[4], buf4[4];
      14  int i;
      15  
      16  int
      17  foo (void)
      18  {
      19    int ret = snprintf (buf1, sizeof buf1, "abcde");
      20    ret += snprintf (buf2, sizeof buf2, "abcdef") * 16;
      21    ret += snprintf (buf3, sizeof buf3, "%s", i++ < 6 ? "abc" : "def") * 256;
      22    ret += snprintf (buf4, sizeof buf4, "%s", i++ > 10 ? "abcde" : "defgh") * 4096;
      23    return ret;
      24  }
      25  
      26  int
      27  main (void)
      28  {
      29    if (foo () != 5 + 6 * 16 + 3 * 256 + 5 * 4096)
      30      abort ();
      31    if (memcmp (buf1, "abcde", 6) != 0
      32        || memcmp (buf2, "abcde", 6) != 0
      33        || memcmp (buf3, "abc", 4) != 0
      34        || memcmp (buf4, "def", 4) != 0
      35        || i != 2)
      36      abort ();
      37    return 0;
      38  }