Debian Codegraph @

gcc/testsuite/gcc.dg/tree-ssa/pr79800.c

raw
1 /* PR 79800 - wrong snprintf result range with precision in a narrow
2 negative-positive range
3 { dg-do "run" { target c99_runtime } }
4 { dg-options "-O2 -Wall" } */
5
6 #define FMT "%.*a"
7 char fmt[] = FMT;
8
9 volatile double x = 1.23456789;
10
11 void f (int p)
12 {
13 if (p < -1 || 0 < p)
14 p = -1;
15
16 char d[30];
17 int n1 = __builtin_sprintf (d, "%.*a", p, x);
18 const char *s = n1 < 20 ? "< 20" : ">= 20";
19
20 if (__builtin_strcmp (s, ">= 20"))
21 __builtin_abort ();
22 }
23
24 volatile int i = -1;
25
26 int main ()
27 {
28 f (i);
29
30 return 0;
31 }