[PATCH] [StaticAnalyzer] New checker StringPlusChar

Jordan Rose jordan_rose at apple.com
Tue Sep 24 19:00:32 PDT 2013


I was sort of right: we have a warning -Wstring-plus-int for adding an integer (or character literal) to a string literal...but nothing for variables. 

Nevertheless, this is a syntactic check rather than a path-sensitive one, so I'd recommend writing it using checkASTCodeBody instead. You can take a look at CheckSizeofPointer.cpp to see how this works, though I'd recommend using the slightly-more-powerful RecursiveASTVisitor (overriding VisitBinaryOperator) rather than building your own recursion with StmtVisitor.

Jordan


On Sep 19, 2013, at 9:23 , Jordan Rose <jordan_rose at apple.com> wrote:

> I could have sworn we had a check or warning for this already, but I don't see it. Hopefully I'll get a chance to review this soon; thanks, Anders!
> 
> Jordan
> 
> 
> On Sep 19, 2013, at 7:46 , Anders Rönnholm <Anders.Ronnholm at evidente.se> wrote:
> 
>> Hi,
>> 
>> This is a new check i want to get reviewed. It checks for char literal additions on strings.
>> 
>> Example:
>> char* str;
>> str = str + 'c';
>> 
>> This is a suspicious pointer arithmetic, probably string addition was intended.
>> 
>> Thanks,
>> Anders
>> 
>> .......................................................................................................................
>> Anders Rönnholm Senior Engineer
>> Evidente ES East AB  Warfvinges väg 34  SE-112 51 Stockholm  Sweden
>> 
>> Mobile:                    +46 (0)70 912 42 54
>> E-mail:                    Anders.Ronnholm at evidente.se
>> 
>> www.evidente.se
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stringpluschar.diff
Type: text/x-patch
Size: 5799 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130924/4a4f5960/attachment.bin>
-------------- next part --------------
>> 
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 



More information about the cfe-commits mailing list