1 /* PR tree-optimization/83431 -Wformat-truncation may incorrectly report
4 { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */
6 typedef __SIZE_TYPE__
size_t;
8 extern int snprintf (char*, size_t, const char*, ...);
9 extern char* strcpy (char*, const char*);
19 void test_assign_nowarn (struct S
* s
)
25 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "%s", a9
); /* { dg-bogus "\\\[-Wformat-truncation]" } */
31 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "%s\n", a8
); /* { dg-bogus "\\\[-Wformat-truncation]" } */
37 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "[%s]", a7
); /* { dg-bogus "\\\[-Wformat-truncation]" } */
43 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "[%s]\n", a6
); /* { dg-bogus "\\\[-Wformat-truncation]" } */
48 void test_strcpy_nowarn (struct S
* s
)
52 strcpy (s
[i
].a9
, "1234");
53 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "%s", s
[i
].a9
);
56 strcpy (s
[i
].a9
, "123");
57 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "%s\n", s
[i
].a9
); /* { dg-bogus "\\\[-Wformat-truncation]" } */
60 strcpy (s
[i
].a9
, "12");
61 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "[%s]", s
[i
].a9
); /* { dg-bogus "\\\[-Wformat-truncation]" } */
64 strcpy (s
[i
].a9
, "1");
65 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "[%s]\n", s
[i
].a9
); /* { dg-bogus "\\\[-Wformat-truncation]" } */
69 void test_warn (struct S
* s
)
72 strcpy (s
[i
].a9
, "12345678");
73 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "%s", s
[i
].a9
); /* { dg-warning "'%s' directive output truncated writing 8 bytes into a region of size 5" } */
76 strcpy (s
[i
].a9
, "1234567");
77 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "%s", s
[i
].a9
); /* { dg-warning "'%s' directive output truncated writing 7 bytes into a region of size 5" } */
80 strcpy (s
[i
].a9
, "123456");
81 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "%s", s
[i
].a9
); /* { dg-warning "'%s' directive output truncated writing 6 bytes into a region of size 5" } */
84 strcpy (s
[i
].a9
, "12345");
85 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "%s", s
[i
].a9
); /* { dg-warning "'snprintf' output truncated before the last format character" } */
88 strcpy (s
[i
].a9
, "1234");
89 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), "%s\n", s
[i
].a9
); /* { dg-warning "output truncated before the last format character" } */
92 strcpy (s
[i
].a9
, "123");
93 snprintf (s
[i
].a5
, sizeof (s
[i
].a5
), ">%s<", s
[i
].a9
); /* { dg-warning "output truncated before the last format character" } */