| 1 |
#include "../../gcc.dg/analyzer/analyzer-decls.h" |
| 2 |
|
| 3 |
/* { dg-additional-options "-fpermissive" { target c++ } } */ |
| 4 |
|
| 5 |
/* Example with multiple params with attribute null_terminated_string_arg. */ |
| 6 |
|
| 7 |
char *example_fn (const char *p, const char *q) |
| 8 |
__attribute__((null_terminated_string_arg (1))) |
| 9 |
__attribute__((null_terminated_string_arg (2))); |
| 10 |
// but can be NULL |
| 11 |
|
| 12 |
char * |
| 13 |
test_passthrough (const char *a, const char *b) |
| 14 |
{ |
| 15 |
return example_fn (a, b); |
| 16 |
} |
| 17 |
|
| 18 |
char * |
| 19 |
test_NULL_str (void) |
| 20 |
{ |
| 21 |
return example_fn (NULL, NULL); /* { dg-bogus "use of NULL where non-null expected" } */ |
| 22 |
} |
| 23 |
|
| 24 |
char * |
| 25 |
test_unterminated_str_1 (void) |
| 26 |
{ |
| 27 |
char str[3] = "abc"; /* { dg-warning "initializer-string for '\[^\n\]*' is too long" "" { target c++ } } */ |
| 28 |
return example_fn (str, NULL); /* { dg-warning "stack-based buffer over-read" } */ |
| 29 |
/* { dg-message "while looking for null terminator for argument 1" "note" { target *-*-* } .-1 } */ |
| 30 |
} |
| 31 |
|
| 32 |
char * |
| 33 |
test_unterminated_str_2 (void) |
| 34 |
{ |
| 35 |
char str[3] = "abc"; /* { dg-warning "initializer-string for '\[^\n\]*' is too long" "" { target c++ } } */ |
| 36 |
return example_fn (NULL, str); /* { dg-warning "stack-based buffer over-read" } */ |
| 37 |
/* { dg-message "while looking for null terminator for argument 2" "note" { target *-*-* } .-1 } */ |
| 38 |
} |
| 39 |
|
| 40 |
char * |
| 41 |
test_uninitialized_str_1 (void) |
| 42 |
{ |
| 43 |
char str[16]; |
| 44 |
return example_fn (str, NULL); /* { dg-warning "use of uninitialized value 'str\\\[0\\\]'" } */ |
| 45 |
} |
| 46 |
|
| 47 |
char * |
| 48 |
test_uninitialized_str_2 (void) |
| 49 |
{ |
| 50 |
char str[16]; |
| 51 |
return example_fn (NULL, str); /* { dg-warning "use of uninitialized value 'str\\\[0\\\]'" } */ |
| 52 |
} |