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