[cfe-dev] Extending printf format string checking to cover ObjC format strings in NSLog

Ted Kremenek kremenek at apple.com
Mon Jun 16 11:38:23 PDT 2008

On Jun 16, 2008, at 3:42 AM, Jean-Daniel Dupas wrote:

> Le 16 juin 08 à 12:28, Nikita Zhuk a écrit :
>> Hello,
>> Current printf format string checking is very useful but it's  
>> limited to printf -style functions which use C format strings. I  
>> would like to propose extending this functionality to cover  
>> Objective-C format strings in NSLog function. A simple  
>> implementation of this extension is attached to this message.
>> Speaking of format strings in ObjC, are there any plans to extend  
>> format string checking to cover ObjC methods which accept format  
>> strings as one of their arguments, such as various -[NSString  
>> initWithFormat:...] methods?
>> Best regards,
>> Nikita Zhuk
> Note that '%@' is also supported in CoreFoundation fonctions:  
> CFStringCreateWithFormat() for example. If the format string  
> checking is extended, you may considere thoses cases and not  limite  
> it to objc sources.

This functionality should eventually go in as well.  The set of such  
CF functions should be small.  Other functions that use Objective-C  
style format strings should generally be labeled with the __NSString__  
attribute.  Unfortunately, it looks like the "initWithFormat:" methods  
do not have this attribute:

(kremenek at grue:Sema)$ pwd
(kremenek at grue:Sema)$ clang -E cocoa.m | grep initWithFormat | grep  
- (id)initWithFormat:(NSString *)format, ...;
- (id)initWithFormat:(NSString *)format arguments:(va_list)argList;
- (id)initWithFormat:(NSString *)format locale:(id)locale, ...;
- (id)initWithFormat:(NSString *)format locale:(id)locale arguments: 

Fortunately, it looks like the set of methods to hardwire support for  
is small.

More information about the cfe-dev mailing list