aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/analyzer/deref-before-check-pr108455-1.c
blob: 5f2ca9669313035b713aa3fd18ab5bfac518b837 (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
extern int could_fail_1 (void);
extern void *could_fail_2 (int);
extern void cleanup (void *);

struct header {
  int signature;
};

int test_1 (void) {
  int fd, ret = 0;
  void *data = ((void *)0);
  struct header *hdr;

  fd = could_fail_1 ();

  if (fd < 0) {
    ret = -1;
    goto cleanup;
  }

  data = could_fail_2 (fd);
  hdr = (struct header *) data;

  if (hdr->signature != 42) {
    ret = -2;
    goto cleanup;
  }

cleanup:
  if (ret) {
    if (data) /* { dg-bogus "check of 'data' for NULL after already dereferencing it" } */
      cleanup (data);
  }

  return ret;
}