aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/analyzer/pr99716-1.c
blob: 2ccdcc73a5c29a34977a3cc629596d43b21a24cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
typedef struct FILE   FILE;

FILE* fopen (const char*, const char*);
int   fclose (FILE*);
int fprintf (FILE *, const char *, ...);

#define NULL ((void *)0)

void
test_1 (void)
{
  int i;

  for (i = 0; i < 2; ++i) {
    FILE *fp = fopen ("/tmp/test", "w");
    fprintf (fp, "hello:%s ", "world");
    fclose (fp); /* { dg-bogus "double 'fclose'" } */
  }
}

void
test_2 (void)
{
  int i;

  for (i = 0; i < 2; ++i) {
    FILE *fp = fopen ("/tmp/test", "w");
    fprintf (fp, "hello");
  }
} /* { dg-warning "leak of FILE 'fp'" } */

FILE *fp3;

void
test_3 (FILE **fpp)
{
  int i;

  for (i = 0; i < 2; ++i) {
    *fpp = fopen ("/tmp/test", "w");
    fprintf (*fpp, "hello");
    fclose (*fpp); /* { dg-bogus "double 'fclose'" } */
    *fpp = NULL;
  }
}