Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/fopen-2.c

raw
1 typedef struct FILE FILE;
2 FILE *fopen (const char *pathname, const char *mode);
3 #include "../../gcc.dg/analyzer/analyzer-decls.h"
4
5 FILE *
6 test_passthrough (const char *pathname, const char *mode)
7 {
8 return fopen (pathname, mode);
9 }
10
11 FILE *
12 test_null_pathname (const char *pathname, const char *mode)
13 {
14 return fopen (NULL, mode);
15 }
16
17 FILE *
18 test_null_mode (const char *pathname)
19 {
20 return fopen (pathname, NULL);
21 }
22
23 FILE *
24 test_simple_r (void)
25 {
26 return fopen ("foo.txt", "r");
27 }
28
29 FILE *
30 test_swapped_args (void)
31 {
32 return fopen ("r", "foo.txt"); /* TODO: would be nice to detect this. */
33 }
34
35 FILE *
36 test_uninitialized_pathname (const char *mode)
37 {
38 char buf[10];
39 return fopen (buf, mode); /* { dg-warning "use of uninitialized value 'buf\\\[0\\\]'" } */
40 /* { dg-message "while looking for null terminator for argument 1 \\('&buf'\\) of 'fopen'..." "event" { target c } .-1 } */
41 /* { dg-message "while looking for null terminator for argument 1 \\('& buf'\\) of 'FILE\\* fopen\\(const char\\*, const char\\*\\)'..." "event" { target c++ } .-2 } */
42 }
43
44 FILE *
45 test_uninitialized_mode (const char *filename)
46 {
47 char buf[10];
48 return fopen (filename, buf); /* { dg-warning "use of uninitialized value 'buf\\\[0\\\]'" } */
49 /* { dg-message "while looking for null terminator for argument 2 \\('&buf'\\) of 'fopen'..." "event" { target c } .-1 } */
50 /* { dg-message "while looking for null terminator for argument 2 \\('& buf'\\) of 'FILE\\* fopen\\(const char\\*, const char\\*\\)'..." "event" { target c++ } .-2 } */
51 }
52