xref: /btstack/tool/misc/fix_null_pointer_checks.cocci (revision 9f4d1a7b899892756bd86e2f59fbd343e400378e)
1*9f4d1a7bSMatthias Ringwald// Replace pointer null checks with boolen operations
2*9f4d1a7bSMatthias Ringwald// inverse version of https://github.com/neomutt/coccinelle/blob/master/null-check.cocci
3*9f4d1a7bSMatthias Ringwald// License: GPLv2
4*9f4d1a7bSMatthias Ringwald
5*9f4d1a7bSMatthias Ringwald@@
6*9f4d1a7bSMatthias Ringwaldtype T;
7*9f4d1a7bSMatthias Ringwaldidentifier I;
8*9f4d1a7bSMatthias Ringwaldstatement S1, S2;
9*9f4d1a7bSMatthias Ringwaldexpression E;
10*9f4d1a7bSMatthias Ringwald@@
11*9f4d1a7bSMatthias Ringwald
12*9f4d1a7bSMatthias RingwaldT *I;
13*9f4d1a7bSMatthias Ringwald
14*9f4d1a7bSMatthias Ringwald(
15*9f4d1a7bSMatthias Ringwald- if (!I)
16*9f4d1a7bSMatthias Ringwald+ if (I == NULL)
17*9f4d1a7bSMatthias RingwaldS1
18*9f4d1a7bSMatthias Ringwald|
19*9f4d1a7bSMatthias Ringwald- if (I)
20*9f4d1a7bSMatthias Ringwald+ if (I != NULL)
21*9f4d1a7bSMatthias RingwaldS1
22*9f4d1a7bSMatthias Ringwald|
23*9f4d1a7bSMatthias Ringwald- if (!I)
24*9f4d1a7bSMatthias Ringwald+ if (I == NULL)
25*9f4d1a7bSMatthias RingwaldS1 else S2
26*9f4d1a7bSMatthias Ringwald|
27*9f4d1a7bSMatthias Ringwald- if (I)
28*9f4d1a7bSMatthias Ringwald+ if (I != NULL)
29*9f4d1a7bSMatthias RingwaldS1 else S2
30*9f4d1a7bSMatthias Ringwald|
31*9f4d1a7bSMatthias Ringwaldif (E) S1 else
32*9f4d1a7bSMatthias Ringwald- if (!I)
33*9f4d1a7bSMatthias Ringwald+ if (I == NULL)
34*9f4d1a7bSMatthias RingwaldS1 else S2
35*9f4d1a7bSMatthias Ringwald|
36*9f4d1a7bSMatthias Ringwaldif (E) S1 else
37*9f4d1a7bSMatthias Ringwald- if (I)
38*9f4d1a7bSMatthias Ringwald+ if (I != NULL)
39*9f4d1a7bSMatthias RingwaldS1 else S2
40*9f4d1a7bSMatthias Ringwald)
41