Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/attr-format-1.c

raw
1 extern int
2 my_printf (void *my_object, const char *my_format, ...)
3 __attribute__ ((format (printf, 2, 3)));
4 /* { dg-message "parameter 2 of 'my_printf' marked as a format string via 'format' attribute" "attr note" { target *-*-* } .-2 } */
5 /* { dg-message "argument 2 of 'my_printf' must be a pointer to a null-terminated string" "arg note" { target *-*-* } .-3 } */
6
7 int test_empty (void *my_object, const char *msg)
8 {
9 return my_printf (my_object, "");
10 }
11
12 int test_percent_s (void *my_object, const char *msg)
13 {
14 return my_printf (my_object, "%s\n", msg);
15 }
16
17 int
18 test_unterminated_format (void *my_object)
19 {
20 char fmt[3] = "abc";
21 return my_printf (my_object, fmt); /* { dg-warning "stack-based buffer over-read" } */
22 /* { dg-message "while looking for null terminator for argument 2 \\('&fmt'\\) of 'my_printf'..." "event" { target *-*-* } .-1 } */
23 }
24
25 int
26 test_uninitialized_format (void *my_object)
27 {
28 char fmt[10];
29 return my_printf (my_object, fmt); /* { dg-warning "use of uninitialized value 'fmt\\\[0\\\]'" } */
30 /* { dg-message "while looking for null terminator for argument 2 \\('&fmt'\\) of 'my_printf'..." "event" { target *-*-* } .-1 } */
31 }