| 1 |
/* { dg-additional-options "-fanalyzer-verbose-state-changes" } */ |
| 2 |
int open(const char *, int mode); |
| 3 |
void close(int fd); |
| 4 |
|
| 5 |
#define O_RDONLY 0 |
| 6 |
#define O_WRONLY 1 |
| 7 |
#define O_RDWR 2 |
| 8 |
|
| 9 |
void test_1 (const char* path) |
| 10 |
{ |
| 11 |
int fd = open (path, O_RDWR); /* { dg-message "meaning: \\{verb: 'acquire', noun: 'resource'\\}" } */ |
| 12 |
if (fd != -1) |
| 13 |
{ |
| 14 |
close(fd); /* { dg-message "meaning: \\{verb: 'release', noun: 'resource'\\}" } */ |
| 15 |
close(fd); /* { dg-warning "double 'close' of file descriptor 'fd' \\\[CWE-1341\\\]" } */ |
| 16 |
} |
| 17 |
} |
| 18 |
|
| 19 |
void test_2 (const char* path) |
| 20 |
{ |
| 21 |
int fd = open (path, O_RDONLY); /* { dg-message "meaning: \\{verb: 'acquire', noun: 'resource'\\}" } */ |
| 22 |
if (fd != -1) |
| 23 |
{ |
| 24 |
close(fd); /* { dg-message "meaning: \\{verb: 'release', noun: 'resource'\\}" } */ |
| 25 |
close(fd); /* { dg-warning "double 'close' of file descriptor 'fd' \\\[CWE-1341\\\]" } */ |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
void test_3 (const char* path) |
| 30 |
{ |
| 31 |
int fd = open (path, O_WRONLY); /* { dg-message "meaning: \\{verb: 'acquire', noun: 'resource'\\}" } */ |
| 32 |
if (fd != -1) |
| 33 |
{ |
| 34 |
close(fd); /* { dg-message "meaning: \\{verb: 'release', noun: 'resource'\\}" } */ |
| 35 |
close(fd); /* { dg-warning "double 'close' of file descriptor 'fd' \\\[CWE-1341\\\]" } */ |
| 36 |
} |
| 37 |
} |