mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-19 20:27:01 +00:00
DEV: coccinelle: add a test to detect unchecked malloc()
The coccinelle test "unchecked-malloc.cocci" detects various cases of unchecked malloc().
This commit is contained in:
parent
7a03ab426f
commit
2ec42bff48
34
dev/coccinelle/unchecked-malloc.cocci
Normal file
34
dev/coccinelle/unchecked-malloc.cocci
Normal file
@ -0,0 +1,34 @@
|
||||
// find calls to malloc
|
||||
@call@
|
||||
expression ptr;
|
||||
position p;
|
||||
@@
|
||||
|
||||
ptr@p = malloc(...);
|
||||
|
||||
// find ok calls to malloc
|
||||
@ok@
|
||||
expression ptr;
|
||||
position call.p;
|
||||
@@
|
||||
|
||||
ptr@p = malloc(...);
|
||||
... when != ptr
|
||||
(
|
||||
(ptr == NULL || ...)
|
||||
|
|
||||
(ptr == 0 || ...)
|
||||
|
|
||||
(ptr != NULL || ...)
|
||||
|
|
||||
(ptr != 0 || ...)
|
||||
)
|
||||
|
||||
// fix bad calls to malloc
|
||||
@depends on !ok@
|
||||
expression ptr;
|
||||
position call.p;
|
||||
@@
|
||||
|
||||
ptr@p = malloc(...);
|
||||
+ if (ptr == NULL) return;
|
Loading…
Reference in New Issue
Block a user