tool/misc: cocci script for if (ptr) operations, (void) memcpy

This commit is contained in:
Matthias Ringwald 2019-12-03 12:23:19 +01:00
parent c10be05f57
commit 9f4d1a7b89
2 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,40 @@
// Replace pointer null checks with boolen operations
// inverse version of https://github.com/neomutt/coccinelle/blob/master/null-check.cocci
// License: GPLv2
@@
type T;
identifier I;
statement S1, S2;
expression E;
@@
T *I;
(
- if (!I)
+ if (I == NULL)
S1
|
- if (I)
+ if (I != NULL)
S1
|
- if (!I)
+ if (I == NULL)
S1 else S2
|
- if (I)
+ if (I != NULL)
S1 else S2
|
if (E) S1 else
- if (!I)
+ if (I == NULL)
S1 else S2
|
if (E) S1 else
- if (I)
+ if (I != NULL)
S1 else S2
)

View File

@ -0,0 +1,6 @@
// Ignore memcpy return
@@
expression E1, E2, E3;
@@
- memcpy(E1, E2, E3)
+ (void) memcpy(E1, E2, E3)