Debian Codegraph @

gcc/testsuite/gcc.dg/Wformat-overflow1.c

raw
1 /*
2 { dg-do compile }
3 { dg-options "-Wformat-overflow -std=c23" }
4 */
5
6 extern int sprintf (char* restrict, const char* restrict, ...);
7
8 void test_warn () {
9
10 int n = __INT_MAX__;
11 char dst [5] = {0};
12 sprintf (dst, "%b", n); /* { dg-warning "-Wformat-overflow" } */
13
14 sprintf (dst, "%#b", n); /* { dg-warning "-Wformat-overflow" } */
15
16 }
17
18 void test_no_warn () {
19
20 char dst [5] = {0};
21 int n = 8;
22 sprintf (dst, "%b", n);
23
24 char another_dst [34] = {0};
25 n = __INT_MAX__;
26 sprintf (another_dst, "%#b", n);
27
28 }