Skip several analyzer socket tests on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / c-c++-common / analyzer / file-1.c
blob316cbb3d8680b358bbfda33230b89b368c0beb47
1 typedef struct FILE FILE;
3 FILE* fopen (const char*, const char*);
4 int fclose (FILE*);
5 #define SEEK_SET 0
6 int fseek (FILE *, long int, int);
8 void
9 test_1 (const char *path)
11 FILE *f = fopen (path, "r"); /* { dg-message "opened here" } */
12 if (!f)
13 return;
15 fclose (f); /* { dg-message "\\(4\\) \\.\\.\\.to here" "to here" } */
16 /* { dg-message "\\(5\\) first 'fclose' here" "first fclose" { target *-*-* } .-1 } */
17 fclose (f); /* { dg-warning "double 'fclose' of FILE 'f' \\\[CWE-1341\\\]" "warning" } */
18 /* { dg-message "second 'fclose' here; first 'fclose' was at \\(5\\)" "second fclose" { target *-*-* } .-1 } */
21 /* Swallow -Wuse-after-free issued for the same problem
22 { dg-prune-output "-Wuse-after-free" } */
24 void
25 test_2 (const char *src, const char *dst)
27 FILE *f_in = fopen (src, "r"); /* { dg-message "\\(1\\) opened here" } */
28 if (!f_in)
29 return;
31 FILE *f_out = fopen (src, "w");
32 if (!f_out)
33 return; /* { dg-warning "leak of FILE 'f_in'" "warning" } */
34 /* { dg-message "\\(7\\) 'f_in' leaks here; was opened at \\(1\\)" "event" { target *-*-* } .-1 } */
36 fclose (f_out);
37 fclose (f_in);
40 void
41 test_3 (const char *path)
43 FILE *f = fopen (path, "r"); /* { dg-message "opened here" } */
44 return; /* { dg-warning "leak of FILE 'f'" } */
47 void
48 test_4 (const char *path)
50 FILE *f = fopen (path, "r"); /* { dg-message "opened here" } */
52 /* Ensure we know about common fns that are known to not close the
53 file (e.g. "fseek"). */
54 fseek (f, 1024, SEEK_SET);
56 return; /* { dg-warning "leak of FILE 'f'" } */
59 void
60 test_5 (const char *path)
62 FILE *f = fopen (path, "r"); /* { dg-message "opened here" } */
63 return; /* { dg-warning "leak of FILE 'f'" } */