1 //#include <stdlib.h>
2 
3 struct foo {
4 	int a;
5 };
6 
7 struct foo *a;
8 struct foo *b;
9 struct foo *c;
10 struct foo *d;
11 int x;
12 
func(void)13 void func (void)
14 {
15 	a = 0;
16 	b = 0;
17 	c = 0;
18 	d = 0;
19 
20 	switch(x) {
21 	case 1:
22 		a = returns_nonnull();
23 		break;
24 	case 2:
25 		b = returns_nonnull();
26 		break;
27 	case 3:
28 		c = returns_nonnull();
29 		break;
30 	default:
31 		d = returns_nonnull();
32 	}
33 
34 	switch(x) {
35 	case 1:
36 		a->a = 1;
37 	case 2:
38 		a->a = 2;
39 		b->a = 3;
40 		break;
41 	case 3:
42 		c->a = 4;
43 		break;
44 	case 4:
45 		d->a = 5;
46 		break;
47 	}
48 }
49 /*
50  * check-name: Smatch switch handling
51  * check-command: smatch --spammy sm_switch.c
52  * check-known-to-fail
53  *
54  * check-output-start
55 sm_switch.c:38 func() warn: missing break? reassigning 'a->a'
56 sm_switch.c:38 func() error: potential NULL dereference 'a'.
57 sm_switch.c:39 func() error: potential NULL dereference 'b'.
58  * check-output-end
59  */
60