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

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

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

When sending error messages, I usually just send an error.localizedDescription message, Example:

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

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

So, I tried something like this:

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

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

+4
2

msgFormat - .   " " otherButton.

NSRunAlertPanel(@"error", @"%@", @"OK", nil, nil, err.localizedDescription);
           message format---^         arguments---^
+8

NSRunAlertPanel . (. NSAlert .)

0

Source: https://habr.com/ru/post/1531039/


All Articles