Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSRunAlertPanel + format string is not a string literal (potentially insecure)

Ok, so I know the format string is not a string literal warning, but I don't know why is it appearing on NSRunAlertPanel, the definition is:

APPKIT_EXTERN NSInteger NSRunAlertPanel(NSString *title, NSString *msgFormat, NSString *defaultButton, NSString *alternateButton, NSString *otherButton, ...) NS_FORMAT_FUNCTION(2,6);

When reporting errors I usually just pass the error.localizedDescription on the message, example:

NSRunAlertPanel(@"error", err.localizedDescription, @"OK",nil,nil);

But after upgrading to xcode 5.1, I started getting this warnings.

So I tried something like this:

NSRunAlertPanel(@"error", [NSString stringWithFormat:@"%@", err.localizedDescription], @"OK", nil, nil);

And its the same situation. Anyone has any ideas on how to fix this ?

like image 619
the Reverend Avatar asked Feb 13 '23 13:02

the Reverend


1 Answers

msgFormat is the message format string and should be a string literal. The necessary arguments are added as "variable argument list" after otherButton. For example

NSRunAlertPanel(@"error", @"%@", @"OK", nil, nil, err.localizedDescription);
           message format---^         arguments---^
like image 111
Martin R Avatar answered Apr 27 '23 20:04

Martin R