coccinelle: fix malloc test

We can have more than an identifier to be assigned the result of
a malloc function.
pull/677/merge
Eric Leblond 12 years ago committed by Victor Julien
parent 6378db89f6
commit a597237aed

@ -1,23 +1,36 @@
@malloced@
identifier x;
expression x;
position p1;
identifier func =~ "(SCMalloc|SCStrdup|SCCalloc|SCMallocAligned|SCRealloc)";
@@
x@p1 = func(...)
@inlinetested@
identifier x;
position p1;
expression x, E;
statement S;
position malloced.p1;
identifier func =~ "(SCMalloc|SCStrdup|SCCalloc|SCMallocAligned|SCRealloc)";
@@
(
if ((x@p1 = func(...)) == NULL) S
|
if (E && (x@p1 = func(...)) == NULL) S
)
@realloc exists@
position malloced.p1;
expression x, E1;
identifier func =~ "(SCMalloc|SCCalloc|SCMallocAligned)";
@@
x@p1 = func(...)
... when != x
x = SCRealloc(x, E1)
@istested@
identifier x;
@istested depends on !realloc exists@
expression x, E1;
position malloced.p1;
statement S1, S2;
identifier func =~ "(SCMalloc|SCStrdup|SCCalloc|SCMallocAligned|SCRealloc)";
@ -28,19 +41,23 @@ x@p1 = func(...)
(
if (unlikely(x == NULL)) S1
|
if (unlikely(x == NULL)) S1 else S2
|
if (likely(x != NULL)) S1
|
if (x == NULL) S1
|
if (x != NULL) S1 else S2
|
if (x && E1) S1
|
BUG_ON(x == NULL)
)
@script:python depends on malloced && !istested && !inlinetested @
@script:python depends on !realloc && !istested && !inlinetested@
p1 << malloced.p1;
@@
print "Structure malloced at %s:%s but error is not checked." % (p1[0].file, p1[0].line)
import sys
sys.exit(1)

Loading…
Cancel
Save