xref: /illumos-gate/usr/src/tools/smatch/src/validation/sm_switch2.c (revision abb88ab1b9516b1ca12094db7f2cfb5d91e0a135)
1 struct foo {
2 	int a;
3 };
4 
5 struct foo *a;
6 struct foo *b;
7 struct foo *c;
8 struct foo *d;
9 int x;
10 
11 void func (void)
12 {
13 	a = 0;
14 	b = 0;
15 	c = 0;
16 	d = 0;
17 
18 	if (x == 1)
19 		a = some_func();
20 	else if (x == 2)
21 		b = some_func();
22 	else if (x == 3)
23 		c = some_func();
24 	else
25 		d = some_func();
26 
27 	switch(x) {
28 	case 1:
29 		a->a = 1;
30 	case 2:
31 		a->a = 2;
32 		b->a = 3;
33 		break;
34 	case 3:
35 		c->a = 4;
36 		break;
37 	case 4:
38 		d->a = 5;
39 		break;
40 	}
41 }
42 /*
43  * check-name: Smatch switch handling #2
44  * check-command: smatch --spammy sm_switch2.c
45  *
46  * check-output-start
47 sm_switch2.c:31 func() warn: missing break? reassigning 'a->a'
48 sm_switch2.c:31 func() error: potential NULL dereference 'a'.
49 sm_switch2.c:32 func() error: potential NULL dereference 'b'.
50  * check-output-end
51  */
52