2 /* { dg-do compile } */
3 /* { dg-options "-O2 -Wformat-truncation -fdiagnostics-show-caret" } */
5 extern int snprintf (char *, __SIZE_TYPE__
, const char *, ...);
8 foo (char *a
, char *b
, char *c
, int d
, int e
)
10 snprintf (a
, 7, "abc\\\123 efg");
11 /* { dg-warning "directive output truncated writing 9 bytes into a region of size 7" "" { target *-*-* } .-1 }
12 { dg-message ".snprintf. output 10 bytes into a destination of size 7" "note" { target *-*-* } .-2 }
13 { dg-begin-multiline-output "" }
14 snprintf (a, 7, "abc\\\123 efg");
16 { dg-end-multiline-output "" }
17 { dg-begin-multiline-output "note" }
18 snprintf (a, 7, "abc\\\123 efg");
19 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 { dg-end-multiline-output "" } */
23 snprintf (b
, 7, "a%dbcdefg", d
);
24 /* { dg-warning "'bcdefg' directive output truncated writing 6 bytes into a region of size 4" "" { target *-*-* } .-1 }
25 { dg-message ".snprintf. output 10 bytes into a destination of size 7" "note" { target *-*-* } .-2 }
26 { dg-begin-multiline-output "" }
27 snprintf (b, 7, "a%dbcdefg", d);
29 { dg-end-multiline-output "" }
30 { dg-begin-multiline-output "note" }
31 snprintf (b, 7, "a%dbcdefg", d);
32 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33 { dg-end-multiline-output "" } */
35 snprintf (c
, 7, "a%dbcdefgh", e
);
36 /* { dg-warning "'bcdefgh' directive output truncated writing 7 bytes into a region of size between 3 and 5" "" { target *-*-* } .-1 }
37 { dg-message ".snprintf. output between 10 and 12 bytes into a destination of size 7" "note" { target *-*-* } .-2 }
38 { dg-begin-multiline-output "" }
39 snprintf (c, 7, "a%dbcdefgh", e);
41 { dg-end-multiline-output "" }
42 { dg-begin-multiline-output "note" }
43 snprintf (c, 7, "a%dbcdefgh", e);
44 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45 { dg-end-multiline-output "" } */