| 1 |
/* { dg-additional-options "-Wno-stringop-overread" } */ |
| 2 |
/* { dg-additional-options "-fpermissive" { target c++ } } */ |
| 3 |
|
| 4 |
#include "../../gcc.dg/analyzer/analyzer-decls.h" |
| 5 |
|
| 6 |
char *example_fn (const char *p, __SIZE_TYPE__ n) /* { dg-message "argument 1 of '\[^\n\r\]*' must be a pointer to a null-terminated string" } */ |
| 7 |
__attribute__((null_terminated_string_arg (1))) |
| 8 |
__attribute__((access (read_only, 1))); // but doesn't identify an argument for a size limit |
| 9 |
|
| 10 |
char * |
| 11 |
test_passthrough (const char* str, __SIZE_TYPE__ n) |
| 12 |
{ |
| 13 |
return example_fn (str, n); |
| 14 |
} |
| 15 |
|
| 16 |
char * |
| 17 |
test_NULL_str_a (void) |
| 18 |
{ |
| 19 |
return example_fn (NULL, 0); /* { dg-bogus "use of NULL where non-null expected" } */ |
| 20 |
} |
| 21 |
|
| 22 |
char * |
| 23 |
test_NULL_str_b (void) |
| 24 |
{ |
| 25 |
return example_fn (NULL, 4); /* { dg-bogus "use of NULL where non-null expected" } */ |
| 26 |
} |
| 27 |
|
| 28 |
char * |
| 29 |
test_unterminated_str (void) |
| 30 |
{ |
| 31 |
char str[3] = "abc"; /* { dg-warning "initializer-string for '\[^\n\]*' is too long" "" { target c++ } } */ |
| 32 |
return example_fn (str, 4); /* { dg-warning "stack-based buffer over-read" } */ |
| 33 |
} |
| 34 |
|
| 35 |
char * |
| 36 |
test_uninitialized_str_a (void) |
| 37 |
{ |
| 38 |
char str[16]; |
| 39 |
return example_fn (str, 1); /* { dg-warning "use of uninitialized value 'str\\\[0\\\]'" } */ |
| 40 |
} |
| 41 |
|
| 42 |
char * |
| 43 |
test_uninitialized_str_b (void) |
| 44 |
{ |
| 45 |
char str[16]; |
| 46 |
return example_fn (str, 16); /* { dg-warning "use of uninitialized value 'str\\\[0\\\]'" } */ |
| 47 |
} |
| 48 |
|
| 49 |
char * |
| 50 |
test_uninitialized_str_c (void) |
| 51 |
{ |
| 52 |
char str[16]; |
| 53 |
return example_fn (str, 17); /* { dg-warning "use of uninitialized value 'str\\\[0\\\]'" } */ |
| 54 |
} |