The problem is in parsing the containing function.  The current attempt to 
parse C++ is not very affective on your code...

In the first case, the problem is the line:

NS_IMETHODIMP nsWindow::SetTitle(const nsString& aTitle)

specifically the & after nsString.  What are the constraints on this &?  
Does it have to appear at the end of an identifier?  Can it only appear on 
a type name?

In the second case, the problem is a new:

input = new char[strlen(acceptLanguage)+1];

It might be possible to recognize new and then treat it as a function 
call.  

You can see these problems using the option -parse_c.  Look for the lines 
that say BAD:!!!!!

julia


On Sun, 6 Feb 2011, Chen Liu wrote:

> Hi,
> 
> I'm trying to use Coccinelle to produce patches for Mozilla code. But I
> encountered some problems. Hope you can help me solve them.
> 
> 1.
> I want to replace a dangerous assignment. So I generate a cocci file:
> @@ identifier titleStr; @@
> (
>  titleStr[destLen - 1] = 0;
> |
> - titleStr[destLen] = 0;
> + titleStr[destLen - 1] = 0;
> )
> But after I spatch the cocci file nothing happens. I attached the source
> file nsWindow.cpp. The assignment appears in line 1896. I looked at the
> source code and found that the variable destLen is defined as the type
> PRInt32. I wonder whether this is a issue that makes the spatch doesn't
> work.
> 
> 2.
> I want to replace a dangerous use of strcpy. The cocci file is:
> @@
> identifier acceptLanguageList, ptrLanguage;
> @@
> - strcpy(acceptLanguageList[i],ptrLanguage[i]);
> +
> strlcpy(acceptLanguageList[i],ptrLanguage[i],sizeof(acceptLanguageList[i]));
> 
> Also nothing happens after the cocci file is spatched. I also attached the
> source file nsLocaleService.cpp. The strcpy appears in line 462.
> 
> Hope you can help me. Thanks in advance!
> 
> Best,
> Chen
> 
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to