File: alias2.c

package info (click to toggle)
splint 1%3A3.1.2%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 21,004 kB
  • sloc: ansic: 150,869; yacc: 3,465; sh: 3,034; makefile: 2,157; lex: 412
file content (64 lines) | stat: -rw-r--r-- 1,001 bytes parent folder | download | duplicates (10)
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
int glob;
int *globp;

int f(int *a, int b, int **c)
{
  int *x, *y, *z;

  {
    {
      int *lx;

      x = a;
      lx = a;
      {
	/*@-shadow@*/ int *lx; /*@=shadow@*/
	
	*lx = 3; /* 1. use before def */
	y = *c;
      }
      *lx = 4; /* 2. modifies a */
    }
    x = y; /* x aliases *c */
    x = *c;
  }

  if (b == *a)
    {
      x = a;   /* okay - x alias a */
      *x = 3;  /* 3. modifies *a */
      y = &glob;
    }
  else
    {
      *x = 3; /* 4. modifies **c */
      y = globp;
    }

  *x = 4; /* 5, 6. bad - may modify *a or **c */
  z = a;

  if ((**c = b) == 3) /* 7. modifies **c */
    {
      *y = 3;    /* 8, 9. may modify glob and *globp */
      globp = a; /* 10. modifies globp */
      a = y; 
      z = globp;
    }
  else
    {
      a = z;
    }

  *a = 3;     /* 11, 12. modifies glob, *globp through y and z */
  *z = 6;     /* 13, 14. modifies *a, *globp */
  *globp = 5; /* 15, 16. modifies *globp, *a */
  return 3;   /* 17. leaves globp aliasing a */
}