check_overflow: store the size in bytes instead of bits.
[smatch.git] / validation / sm_null_deref.c
blobb32d697ddf249b66e323889b727aa2a3b639ca44
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 = 2;
47 if (ac) {
48 d->a = 2;
52 * check-name: Null Dereferences
53 * check-command: smatch --spammy sm_null_deref.c
55 * check-output-start
56 sm_null_deref.c +18 func(6) error: dereferencing undefined: 'aa'
57 sm_null_deref.c +18 func(6) error: potentially derefencing uninitialized 'aa'.
58 sm_null_deref.c +23 func(11) error: dereferencing undefined: 'a'
59 sm_null_deref.c +25 func(13) warn: variable dereferenced before check 'a'
60 sm_null_deref.c +30 func(18) error: dereferencing undefined: 'b'
61 sm_null_deref.c +48 func(36) error: dereferencing undefined: 'd'
62 sm_null_deref.c +48 func(36) error: potential null derefence 'd'.
63 * check-output-end