On Sun, 9 Jan 2011, Chen Liu wrote:

> Hi,
> 
> I couldn't produce a right cocci file for my use. My goal is to replace a
> wrong sprintf call with a right one. So I wrote a cocci file like:
> 
> @@ identifier pBuf;@@
> (
>  sprintf(pBuf+strlen(pBuf), "%s\n",
> PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name);
> |
> - sprintf(pBuf, "%s%s\n", pBuf,
> PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name);
> + sprintf(pBuf+strlen(pBuf), "%s\n",
> PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name);
> )
> 
> However, after I spatched the cocci file, nothing happened. No errors and no
> warnings. I checked the source file (
> http://lxr.linux.no/#linux+v2.6.29/drivers/staging/rt2860/common/cmm_info.c)
> and found that the pBuf is defined as type "IN PUCHAR". I realized that it's
> not a kind of "identifier". But how should I write the cocci file? Could you
> help me?

Even though pBuf has a certain type, it is still considered to be an 
identifier.  The problem is that it is not able to parse probably anything 
in the code because of the IN declarations and some other problems.

What you should do in general is run spatch -parse_c file.c and then you 
can see where are the parsing problems.  It will print out a lot of 
messages, but the most useful part is at the end, where it tells you what 
were the most common problems.  Then you can follow the examples in 
coccinelle/standard.h (I'm not sure where this file is located if you 
don't have the sources, but it should be somewhere) to define the macros 
that are needed for parsing your code.  In your case, with the following 
definitions I was able to parse the entire file:

#define IN
#define OUT
#define IF_DEV_CONFIG_OPMODE_ON_STA(x) MACROSTATEMENT

Just put these in some file macro.h and then always run spatch with the 
option -macro_file macro.h

julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to