[PATCH] [StaticAnalyzer] New checker StringPlusChar

Anders Rönnholm Anders.Ronnholm at evidente.se
Mon Sep 30 03:25:06 PDT 2013


Hi Jordan,

Thank you for your comments. I have changed the check to use RecursiveASTVisitor. However i'm not sure what i should write as category in bugreport. You mentioned adding a new category in CommonBugCategories for SIzeofOnExpression, should i do that or is what i have enough for now? 

I have provided a new diff.

//Anders

From: Jordan Rose [mailto:jordan_rose at apple.com]
Sent: den 25 september 2013 04:01
To: Anders Rönnholm
Cc: cfe-commits at cs.uiuc.edu
Subject: Re: [PATCH] [StaticAnalyzer] New checker StringPlusChar

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<mailto: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<mailto: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<mailto:Anders.Ronnholm at evidente.se>
>>
>> www.evidente.se<http://www.evidente.se>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu<mailto:cfe-commits at cs.uiuc.edu>
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stringpluschar.diff
Type: text/x-patch
Size: 6309 bytes
Desc: stringpluschar.diff
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130930/ef6eb7dd/attachment.bin>


More information about the cfe-commits mailing list