Fix analyzer warnings

This commit is contained in:
Michael Kirk 2018-07-17 20:20:31 -06:00
parent baacebc956
commit ef9a0880ae
11 changed files with 42 additions and 20 deletions

View File

@ -3906,10 +3906,13 @@
buildSettings = { buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ADDRESS_SANITIZER_CONTAINER_OVERFLOW = YES;
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES; CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES; CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES; CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CLANG_UNDEFINED_BEHAVIOR_SANITIZER_INTEGER = YES;
CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES;
CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements; CODE_SIGN_ENTITLEMENTS = Signal/Signal.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@ -3972,6 +3975,7 @@
buildSettings = { buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ADDRESS_SANITIZER_CONTAINER_OVERFLOW = NO;
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES; CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES; CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES; CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;

View File

@ -76,6 +76,9 @@
buildConfiguration = "Debug" buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
enableAddressSanitizer = "YES"
enableASanStackUseAfterReturn = "YES"
enableUBSanitizer = "YES"
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"

View File

@ -278,6 +278,7 @@ static NSTimeInterval launchStartedAt;
} }
OWSBackgroundTask *_Nullable backgroundTask = [OWSBackgroundTask backgroundTaskWithLabelStr:__PRETTY_FUNCTION__]; OWSBackgroundTask *_Nullable backgroundTask = [OWSBackgroundTask backgroundTaskWithLabelStr:__PRETTY_FUNCTION__];
SUPPRESS_DEADSTORE_WARNING(backgroundTask);
if ([NSFileManager.defaultManager fileExistsAtPath:OWSPrimaryStorage.legacyDatabaseFilePath]) { if ([NSFileManager.defaultManager fileExistsAtPath:OWSPrimaryStorage.legacyDatabaseFilePath]) {
DDLogInfo(@"%@ Legacy Database file size: %@", DDLogInfo(@"%@ Legacy Database file size: %@",
@ -925,7 +926,7 @@ static NSTimeInterval launchStartedAt;
- (void)application:(UIApplication *)application - (void)application:(UIApplication *)application
handleActionWithIdentifier:(NSString *)identifier handleActionWithIdentifier:(NSString *)identifier
forLocalNotification:(UILocalNotification *)notification forLocalNotification:(UILocalNotification *)notification
completionHandler:(void (^)(void))completionHandler completionHandler:(void (^)())completionHandler
{ {
OWSAssertIsOnMainThread(); OWSAssertIsOnMainThread();

View File

@ -204,6 +204,7 @@
// TODO: Always show backup when we go to production. // TODO: Always show backup when we go to production.
BOOL isBackupEnabled = [OWSBackup.sharedManager isBackupEnabled]; BOOL isBackupEnabled = [OWSBackup.sharedManager isBackupEnabled];
BOOL showBackup = isBackupEnabled; BOOL showBackup = isBackupEnabled;
SUPPRESS_DEADSTORE_WARNING(showBackup);
#ifdef DEBUG #ifdef DEBUG
showBackup = YES; showBackup = YES;
#endif #endif

View File

@ -331,7 +331,9 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(self.quotedTextLabel); OWSAssert(self.quotedTextLabel);
UIColor *textColor = self.quotedTextColor; UIColor *textColor = self.quotedTextColor;
SUPPRESS_DEADSTORE_WARNING(textColor);
UIFont *font = self.quotedTextFont; UIFont *font = self.quotedTextFont;
SUPPRESS_DEADSTORE_WARNING(font);
NSString *text = @""; NSString *text = @"";
NSString *_Nullable fileTypeForSnippet = [self fileTypeForSnippet]; NSString *_Nullable fileTypeForSnippet = [self fileTypeForSnippet];

View File

@ -1413,13 +1413,12 @@ typedef enum : NSUInteger {
UIColor *subtitleColor = [UIColor.ows_navbarTitleColor colorWithAlphaComponent:(CGFloat)0.9]; UIColor *subtitleColor = [UIColor.ows_navbarTitleColor colorWithAlphaComponent:(CGFloat)0.9];
if (self.thread.isMuted) { if (self.thread.isMuted) {
// Show a "mute" icon before the navigation bar subtitle if this thread is muted. // Show a "mute" icon before the navigation bar subtitle if this thread is muted.
[subtitleText [subtitleText appendAttributedString:[[NSAttributedString alloc]
appendAttributedString:[[NSAttributedString alloc] initWithString:LocalizationNotNeeded(@"\ue067 ")
initWithString:@"\ue067 " attributes:@{
attributes:@{ NSFontAttributeName : [UIFont ows_elegantIconsFont:7.f],
NSFontAttributeName : [UIFont ows_elegantIconsFont:7.f], NSForegroundColorAttributeName : subtitleColor
NSForegroundColorAttributeName : subtitleColor }]];
}]];
} }
BOOL isVerified = YES; BOOL isVerified = YES;
@ -1432,13 +1431,12 @@ typedef enum : NSUInteger {
} }
if (isVerified) { if (isVerified) {
// Show a "checkmark" icon before the navigation bar subtitle if this thread is verified. // Show a "checkmark" icon before the navigation bar subtitle if this thread is verified.
[subtitleText [subtitleText appendAttributedString:[[NSAttributedString alloc]
appendAttributedString:[[NSAttributedString alloc] initWithString:LocalizationNotNeeded(@"\uf00c ")
initWithString:@"\uf00c " attributes:@{
attributes:@{ NSFontAttributeName : [UIFont ows_fontAwesomeFont:10.f],
NSFontAttributeName : [UIFont ows_fontAwesomeFont:10.f], NSForegroundColorAttributeName : subtitleColor,
NSForegroundColorAttributeName : subtitleColor, }]];
}]];
} }
if (self.userLeftGroup) { if (self.userLeftGroup) {

View File

@ -371,7 +371,7 @@ NS_ASSUME_NONNULL_BEGIN
} else { } else {
if ([thread isMuted]) { if ([thread isMuted]) {
[snippetText appendAttributedString:[[NSAttributedString alloc] [snippetText appendAttributedString:[[NSAttributedString alloc]
initWithString:@"\ue067 " initWithString:LocalizationNotNeeded(@"\ue067 ")
attributes:@{ attributes:@{
NSFontAttributeName : [UIFont ows_elegantIconsFont:9.f], NSFontAttributeName : [UIFont ows_elegantIconsFont:9.f],
NSForegroundColorAttributeName : NSForegroundColorAttributeName :

View File

@ -329,7 +329,7 @@ NS_ASSUME_NONNULL_BEGIN
[alert addAction:[UIAlertAction actionWithTitle:CommonStrings.dismissButton [alert addAction:[UIAlertAction actionWithTitle:CommonStrings.dismissButton
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
[_challengeTextField becomeFirstResponder]; [self.challengeTextField becomeFirstResponder];
}]]; }]];
[self presentViewController:alert animated:YES completion:nil]; [self presentViewController:alert animated:YES completion:nil];

View File

@ -354,7 +354,7 @@ typedef void (^CustomLayoutBlock)(void);
// Show a "checkmark" if this user is verified. // Show a "checkmark" if this user is verified.
[labelText [labelText
appendAttributedString:[[NSAttributedString alloc] appendAttributedString:[[NSAttributedString alloc]
initWithString:@"\uf00c " initWithString:LocalizationNotNeeded(@"\uf00c ")
attributes:@{ attributes:@{
NSFontAttributeName : [UIFont NSFontAttributeName : [UIFont
ows_fontAwesomeFont:self.verificationStateLabel.font.pointSize], ows_fontAwesomeFont:self.verificationStateLabel.font.pointSize],
@ -383,7 +383,7 @@ typedef void (^CustomLayoutBlock)(void);
// Show a "checkmark" if this user is not verified. // Show a "checkmark" if this user is not verified.
[buttonText [buttonText
appendAttributedString:[[NSAttributedString alloc] appendAttributedString:[[NSAttributedString alloc]
initWithString:@"\uf00c " initWithString:LocalizationNotNeeded(@"\uf00c ")
attributes:@{ attributes:@{
NSFontAttributeName : [UIFont NSFontAttributeName : [UIFont
ows_fontAwesomeFont:self.verifyUnverifyButtonLabel.font.pointSize], ows_fontAwesomeFont:self.verifyUnverifyButtonLabel.font.pointSize],

View File

@ -786,7 +786,7 @@ const CGFloat kIconViewLength = 24;
NSMutableAttributedString *subtitle = [NSMutableAttributedString new]; NSMutableAttributedString *subtitle = [NSMutableAttributedString new];
// "checkmark" // "checkmark"
[subtitle appendAttributedString:[[NSAttributedString alloc] [subtitle appendAttributedString:[[NSAttributedString alloc]
initWithString:@"\uf00c " initWithString:LocalizationNotNeeded(@"\uf00c ")
attributes:@{ attributes:@{
NSFontAttributeName : NSFontAttributeName :
[UIFont ows_fontAwesomeFont:kSubtitlePointSize], [UIFont ows_fontAwesomeFont:kSubtitlePointSize],

View File

@ -137,6 +137,19 @@ NS_ASSUME_NONNULL_BEGIN
OWSCFail(_messageFormat, ##__VA_ARGS__); \ OWSCFail(_messageFormat, ##__VA_ARGS__); \
} }
// Avoids Clang analyzer warning:
// Value stored to 'x' during it's initialization is never read
#define SUPPRESS_DEADSTORE_WARNING(x) \
do { \
(void)x; \
} while (0)
__attribute__((annotate("returns_localized_nsstring"))) static inline NSString *LocalizationNotNeeded(NSString *s)
{
return s;
}
// This function is intended for use in Swift. // This function is intended for use in Swift.
void SwiftAssertIsOnMainThread(NSString *functionName); void SwiftAssertIsOnMainThread(NSString *functionName);