| 1 |
#include "../../gcc.dg/analyzer/analyzer-decls.h" |
| 2 |
|
| 3 |
/* { dg-additional-options "-fpermissive" { target c++ } } */ |
| 4 |
|
| 5 |
char *example_fn (const char *p) /* { dg-message "argument 1 of '\[^\n\r\]*' must be a pointer to a null-terminated string" } */ |
| 6 |
__attribute__((null_terminated_string_arg (1))); |
| 7 |
// but can be NULL |
| 8 |
|
| 9 |
char * |
| 10 |
test_passthrough (const char* str) |
| 11 |
{ |
| 12 |
return example_fn (str); |
| 13 |
} |
| 14 |
|
| 15 |
char * |
| 16 |
test_NULL_str (void) |
| 17 |
{ |
| 18 |
return example_fn (NULL); /* { dg-bogus "use of NULL where non-null expected" } */ |
| 19 |
} |
| 20 |
|
| 21 |
char * |
| 22 |
test_unterminated_str (void) |
| 23 |
{ |
| 24 |
char str[3] = "abc"; /* { dg-warning "initializer-string for '\[^\n\]*' is too long" "" { target c++ } } */ |
| 25 |
return example_fn (str); /* { dg-warning "stack-based buffer over-read" } */ |
| 26 |
/* { dg-message "while looking for null terminator for argument 1" "note" { target *-*-* } .-1 } */ |
| 27 |
} |
| 28 |
|
| 29 |
char * |
| 30 |
test_uninitialized_str (void) |
| 31 |
{ |
| 32 |
char str[16]; |
| 33 |
return example_fn (str); /* { dg-warning "use of uninitialized value 'str\\\[0\\\]'" } */ |
| 34 |
} |