| 1 |
/* { dg-additional-options "-fanalyzer-verbosity=3" } */ |
| 2 |
|
| 3 |
typedef struct FILE FILE; |
| 4 |
|
| 5 |
FILE* fopen (const char*, const char*); |
| 6 |
int fclose (FILE*); |
| 7 |
char *fgets (char *, int, FILE *); |
| 8 |
|
| 9 |
#define NULL ((void *)0) |
| 10 |
|
| 11 |
|
| 12 |
/* Verify that we correctly emit CFG events in the face of buffers |
| 13 |
being clobbered in these leak reports. */ |
| 14 |
|
| 15 |
void f1 (const char *str) |
| 16 |
{ |
| 17 |
FILE * fp = fopen(str, "r"); /* { dg-message "opened here" } */ |
| 18 |
char buf[10]; |
| 19 |
|
| 20 |
while (fgets(buf, 10, fp) != NULL) /* { dg-message "following 'false' branch\\.\\.\\." } */ |
| 21 |
{ |
| 22 |
} |
| 23 |
} /* { dg-warning "leak of FILE 'fp'" "warning" } */ |
| 24 |
/* { dg-message "\\.\\.\\.to here" "to here" { target *-*-* } .-1 } */ |
| 25 |
|
| 26 |
void f2(const char *str, int flag) |
| 27 |
{ |
| 28 |
FILE * fp = fopen(str, "r"); /* { dg-message "opened here" } */ |
| 29 |
char buf[10]; |
| 30 |
|
| 31 |
if (flag) /* { dg-message "when 'flag == 0'" } */ |
| 32 |
fclose(fp); |
| 33 |
} /* { dg-warning "leak of FILE 'fp'" "warning" } */ |
| 34 |
/* { dg-message "\\.\\.\\.to here" "to here" { target *-*-* } .-1 } */ |