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