Hi,
I've tried going over our codebase with the following script, to find
places where memory allocations are not checked before usage:
@@
identifier ptr, fld;
@@
* ptr = dMemAlloc(...)
... when != (ptr != NULL)
* ptr->fld
dMemAlloc() is a wrapper around malloc().
The script works as I intended it to, but I have run into a problem
with a false positive:
--- ./logf.c 2010-05-10 14:22:02.000000000 +0200
+++ /tmp/nothing/qqlogf.c
@@ -85,14 +85,12 @@ logFd_t *logfOpen (const char *filename,
}
/* Allocate memory for logfile descriptor */
- if ( (fd = dMemAlloc(sizeof(*fd))) == NULL ) {
dLog (logSys, "logfOpen: failed to dMemAlloc(%u bytes), error %s",
sizeof(*fd), dErrTxt()) ;
fclose (fp) ;
return NULL ;
}
- FSTRNCPY (fd->filename, filename) ;
fd->fp = fp ;
I'm not really sure how to catch the error handling, that end us in
the return here. My best guess at a solution is this
... when != (
(ptr != NULL)
|
return
)
But that doesn't even parse, so I'm a bit lost here. Is there a
negative form of when any, I could use here, or should I catch this in
an entirely different way?
--
/Wegge
Leder efter redundant peering af dk.*,linux.debian.*
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)