aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/analyzer/paths-3.c
blob: 1a4a81350c19937cff6084da9855e0de738f1c17 (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
46
47
48
/* { dg-additional-options "-fanalyzer-transitivity" } */
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */

#include <stdlib.h>
#include "analyzer-decls.h"

int test_1 (int a, int b)
{
  void *p;

  if (a > 5)
    if (b)
      p = malloc (16);
    else
      p = malloc (32);

  __analyzer_dump_exploded_nodes (0); /* { dg-warning "3 processed enodes" } */

  if (a > 5)
    {
      free (p);
      __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
    }

  return 0; /* { dg-bogus "leak" } */
}

int test_2 (int a, int b)
{
  void *p;

  if (a > 5)
    if (b)
      p = malloc (16);
    else
      p = malloc (32);

  __analyzer_dump_exploded_nodes (0); /* { dg-warning "3 processed enodes" } */

  if (a > 6) /* different condition */
    {
      free (p);
      __analyzer_dump_exploded_nodes (0); /* { dg-warning "1 processed enode" } */
    }

  return 0; /* { dg-warning "leak of 'p'" } */
  /* leaks when a == 5.  */
}