Add validation script for check_null_deref.c
[smatch.git] / validation / sm_null_deref.c
blobfebdc063b449ebe8773f463590c8c77cebeffddc
1 #include <stdlib.h>
3 struct foo {
4 int a;
5 };
7 struct foo a;
8 struct foo b;
9 struct foo c;
10 struct foo d;
12 static void func (void)
14 struct foo *aa;
15 int ab = 0;
16 int ac = 1;
18 aa->a = 1;
20 if (a) {
21 a->a = 1;
23 a->a = 1;
25 if (a && b) {
26 b->a = 1;
29 if (a || b) {
30 b->a = 1;
33 if (c) {
34 ab = 1;
37 if (ab) {
38 c->a = 1;
41 d = 0;
42 if (c) {
43 d = malloc(sizeof(*d));
44 ac = 1;
47 if (ac) {
48 d->a = 2;
52 * check-name: Null Dereferences
53 * check-command: smatch sm_null_deref.c
55 * check-output-start
56 sm_null_deref.c +18 func(6) Dereferencing Undefined: 'aa'
57 sm_null_deref.c +23 func(11) Dereferencing Undefined: 'a'
58 sm_null_deref.c +30 func(18) Dereferencing Undefined: 'b'
59 sm_null_deref.c +48 func(36) Dereferencing Undefined: 'd'
60 * check-output-end