mirror of
https://github.com/haproxy/haproxy.git
synced 2026-02-19 02:29:31 -05:00
The coccinelle test "unchecked-malloc.cocci" detects various cases of unchecked malloc().
34 lines
413 B
Text
34 lines
413 B
Text
// 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;
|