File: keep.c

package info (click to toggle)
splint 3.1.2.dfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,732 kB
  • ctags: 16,317
  • sloc: ansic: 150,320; yacc: 3,463; sh: 3,003; makefile: 2,153; lex: 412
file content (66 lines) | stat: -rw-r--r-- 949 bytes parent folder | download | duplicates (11)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*@only@*/ int *oglob;
/*@keep@*/ int *kglob;

void f1 (/*@keep@*/ int *x)
{
  kglob = x;
  return;
}

void f2 (/*@keep@*/ int *x)
{
  free (x); /* 1. Keep storage passed as only param: x */
}

int f3 (/*@keep@*/ int *x)
{
  int *y = malloc (sizeof (int));

  if (y == NULL) return 3; /* 2. Keep storage not transferred before return: x */

  *y = 3;

  f1 (x);
  f1 (y);

  return *x;
}

int f4 (/*@only@*/ int *x)
{
  return (f3 (x)); 
}

void f5 (/*@unused@*/ /*@keep@*/ int *x)
{
  return; /* 3. Keep storage not transferred before return: x */
}

void f6 (/*@keep@*/ int *x)
{
  if (*x > 3)
    {
      f2 (x);
    } /* 4. Variable x is kept in true branch, but live in continuation. */

  f2 (x); /* 5. Kept storage passed as keep: f2 (x) */
}

/*@null@*/ int *f7 (/*@null@*/ /*@keep@*/ int *x)
{
  if (x == NULL)
    {
      ;
    }
  else
    {
      f2 (x);
    } 

  return x; /* 6. Kept storage x returned as implicitly only: x */
}