Skip to content
Permalink
Browse files

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

  • Loading branch information
mringwal committed Dec 3, 2019
1 parent c10be05 commit 9f4d1a7b899892756bd86e2f59fbd343e400378e
Showing with 46 additions and 0 deletions.
  1. +40 −0 tool/misc/fix_null_pointer_checks.cocci
  2. +6 −0 tool/misc/ignore_return_mempcy.cocci
@@ -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
)
@@ -0,0 +1,6 @@
// Ignore memcpy return
@@
expression E1, E2, E3;
@@
- memcpy(E1, E2, E3)
+ (void) memcpy(E1, E2, E3)

0 comments on commit 9f4d1a7

Please sign in to comment.
You can’t perform that action at this time.