File: controlflow.c

package info (click to toggle)
cppcheck 1.86-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 14,600 kB
  • sloc: cpp: 169,157; python: 6,329; ansic: 3,848; xml: 847; makefile: 563; sh: 429; cs: 291
file content (73 lines) | stat: -rw-r--r-- 1,009 bytes parent folder | download | duplicates (2)
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
67
68
69
70
71
72
73

//////////////////////////////
// control flow analysis
//////////////////////////////

int buf[2];

void in_if(int a) {
  if (a==100)
    buf[a] = 0; // BUG
}

void before_if(int a) {
  buf[a] = 0; // WARNING
  if (a==100) {}
}

void after_if(int a) {
  if (a==100) {}
  buf[a] = 0; // WARNING
}

void in_for(void) {
  int x;
  for (x = 0; x<100; x++) {
    buf[x] = 0; // BUG
  }
}

void after_for(void) {
  int x;
  for (x = 0; x<100; x++) {}
  buf[x] = 0; // BUG
}

void in_switch(int x) {
  switch (x) {
  case 100:
    buf[x] = 0; // BUG
    break;
  }
}

void before_switch(int x) {
  buf[x] = 0; // WARNING
  switch (x) {
  case 100:
    break;
  }
}

void after_switch(int x) {
  switch (x) {
  case 100:
    break;
  }
  buf[x] = 0; // WARNING
}

void in_while(void) {
  int x = 0;
  while (x<100) {
    buf[x] = 0; // BUG
    x++;
  }
}

void after_while(void) {
  int x = 0;
  while (x<100)
    x++;
  buf[x] = 0; // BUG
}