| 1 |
#include "analyzer-decls.h" |
| 2 |
|
| 3 |
extern int errno; |
| 4 |
|
| 5 |
extern void error (int __status, int __errnum, const char *__format, ...) |
| 6 |
__attribute__ ((__format__ (__printf__, 3, 4))); |
| 7 |
|
| 8 |
extern void error_at_line (int __status, int __errnum, const char *__fname, |
| 9 |
unsigned int __lineno, const char *__format, ...) |
| 10 |
__attribute__ ((__format__ (__printf__, 5, 6))); |
| 11 |
|
| 12 |
/* When status is an unknown param. */ |
| 13 |
|
| 14 |
void test_1 (int st) |
| 15 |
{ |
| 16 |
error (st, errno, "test"); |
| 17 |
__analyzer_eval (st == 0); /* { dg-warning "TRUE" } */ |
| 18 |
} |
| 19 |
|
| 20 |
/* When status is known zero. */ |
| 21 |
|
| 22 |
void test_2 (int st) |
| 23 |
{ |
| 24 |
error (0, errno, "test"); |
| 25 |
__analyzer_dump_path (); /* { dg-message "here" } */ |
| 26 |
} |
| 27 |
|
| 28 |
/* When status is a non-zero known constant. */ |
| 29 |
|
| 30 |
void test_3 (int st) |
| 31 |
{ |
| 32 |
error (1, errno, "test"); |
| 33 |
__analyzer_dump_path (); /* { dg-bogus "here" } */ |
| 34 |
} |
| 35 |
|
| 36 |
/* When status has been tested against zero. */ |
| 37 |
|
| 38 |
void test_4 (int st) |
| 39 |
{ |
| 40 |
if (st) |
| 41 |
{ |
| 42 |
error (st, errno, "nonzero branch"); |
| 43 |
__analyzer_dump_path (); /* { dg-bogus "here" } */ |
| 44 |
} |
| 45 |
else |
| 46 |
{ |
| 47 |
error (st, errno, "zero branch"); |
| 48 |
__analyzer_dump_path (); /* { dg-message "here" } */ |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
/* Similarly for error_at_line. */ |
| 53 |
|
| 54 |
void test_5 (int st) |
| 55 |
{ |
| 56 |
error_at_line (st, errno, __FILE__, __LINE__, "test"); |
| 57 |
__analyzer_eval (st == 0); /* { dg-warning "TRUE" } */ |
| 58 |
} |
| 59 |
|
| 60 |
/* Non-trivial format string. */ |
| 61 |
|
| 62 |
void test_6 (int st, const char *str) |
| 63 |
{ |
| 64 |
error (st, errno, "test: %s", str); |
| 65 |
__analyzer_eval (st == 0); /* { dg-warning "TRUE" } */ |
| 66 |
} |
| 67 |
|
| 68 |
char *test_error_unterminated (int st) |
| 69 |
{ |
| 70 |
char fmt[3] = "abc"; |
| 71 |
error (st, errno, fmt); /* { dg-warning "stack-based buffer over-read" } */ |
| 72 |
/* { dg-message "while looking for null terminator for argument 3 \\('&fmt'\\) of 'error'..." "event" { target *-*-* } .-1 } */ |
| 73 |
} |
| 74 |
|
| 75 |
char *test_error_at_line_unterminated (int st, int errno) |
| 76 |
{ |
| 77 |
char fmt[3] = "abc"; |
| 78 |
error_at_line (st, errno, __FILE__, __LINE__, fmt); /* { dg-warning "stack-based buffer over-read" } */ |
| 79 |
/* { dg-message "while looking for null terminator for argument 5 \\('&fmt'\\) of 'error_at_line'..." "event" { target *-*-* } .-1 } */ |
| 80 |
} |
| 81 |
|
| 82 |
char *test_error_uninitialized (int st, int errno) |
| 83 |
{ |
| 84 |
char fmt[16]; |
| 85 |
error (st, errno, fmt); /* { dg-warning "use of uninitialized value 'fmt\\\[0\\\]'" } */ |
| 86 |
/* { dg-message "while looking for null terminator for argument 3 \\('&fmt'\\) of 'error'..." "event" { target *-*-* } .-1 } */ |
| 87 |
} |
| 88 |
|
| 89 |
char *test_error_at_line_uninitialized (int st, int errno) |
| 90 |
{ |
| 91 |
char fmt[16]; |
| 92 |
error_at_line (st, errno, __FILE__, __LINE__, fmt); /* { dg-warning "use of uninitialized value 'fmt\\\[0\\\]'" } */ |
| 93 |
/* { dg-message "while looking for null terminator for argument 5 \\('&fmt'\\) of 'error_at_line'..." "event" { target *-*-* } .-1 } */ |
| 94 |
} |