]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/tree-ssa/builtin-snprintf-warn-6.c
Add new test [PR78969].
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / builtin-snprintf-warn-6.c
1 /* PR tree-optimization/78969 - bogus snprintf truncation warning due to
2 missing range info
3 { dg-do compile }
4 { dg-options "-O2 -Wall -Wformat-truncation=2" } */
5
6 typedef __SIZE_TYPE__ size_t;
7
8 extern int snprintf (char*, size_t, const char*, ...);
9
10
11 void f (unsigned j, char *p)
12 {
13 if (j > 999)
14 j = 0;
15
16 snprintf (p, 4, "%3u", j);
17 }
18
19 void g (unsigned j, char *p)
20 {
21 if (j > 999)
22 return;
23
24 snprintf (p, 4, "%3u", j); // { dg-bogus "-Wformat-truncation" }
25 }
26
27
28 void pr78969_c4 (char * p /* NNN\0" */)
29 {
30 for (int idx = 0; idx < 1000; idx++) {
31 // guaranteed to be in [0-999] range
32 snprintf (p, 4, "%d", idx); // { dg-bogus "-Wformat-truncation" }
33 }
34 }
35
36
37 void sink (int, ...);
38
39 char d[4];
40
41 void pr78969_c12 (unsigned i)
42 {
43 if (i >= 1000 && i < 10000)
44 snprintf (d, 4, "%3d", i / 10); // { dg-bogus "-Wformat-truncation" }
45 else
46 sink (i / 10 % 10);
47 }