From ef9a0880ae82334d9e9042951fb34cac7cb8da8c Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 17 Jul 2018 20:20:31 -0600 Subject: [PATCH] Fix analyzer warnings --- Signal.xcodeproj/project.pbxproj | 4 +++ .../xcshareddata/xcschemes/Signal.xcscheme | 3 +++ Signal/src/AppDelegate.m | 3 ++- .../AppSettings/AppSettingsViewController.m | 1 + .../Cells/OWSQuotedMessageView.m | 2 ++ .../ConversationViewController.m | 26 +++++++++---------- .../ViewControllers/HomeView/HomeViewCell.m | 2 +- .../CodeVerificationViewController.m | 2 +- .../FingerprintViewController.m | 4 +-- .../OWSConversationSettingsViewController.m | 2 +- SignalServiceKit/src/Util/OWSAsserts.h | 13 ++++++++++ 11 files changed, 42 insertions(+), 20 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 77943b6aa..6cd95074f 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -3906,10 +3906,13 @@ buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ADDRESS_SANITIZER_CONTAINER_OVERFLOW = YES; CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES; CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES; CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = 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_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -3972,6 +3975,7 @@ buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ADDRESS_SANITIZER_CONTAINER_OVERFLOW = NO; CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES; CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES; CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES; diff --git a/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme b/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme index 66624d75a..7dd0b1819 100644 --- a/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme +++ b/Signal.xcodeproj/xcshareddata/xcschemes/Signal.xcscheme @@ -76,6 +76,9 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + enableAddressSanitizer = "YES" + enableASanStackUseAfterReturn = "YES" + enableUBSanitizer = "YES" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 083c4b8fb..1b4f31e50 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -278,6 +278,7 @@ static NSTimeInterval launchStartedAt; } OWSBackgroundTask *_Nullable backgroundTask = [OWSBackgroundTask backgroundTaskWithLabelStr:__PRETTY_FUNCTION__]; + SUPPRESS_DEADSTORE_WARNING(backgroundTask); if ([NSFileManager.defaultManager fileExistsAtPath:OWSPrimaryStorage.legacyDatabaseFilePath]) { DDLogInfo(@"%@ Legacy Database file size: %@", @@ -925,7 +926,7 @@ static NSTimeInterval launchStartedAt; - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification - completionHandler:(void (^)(void))completionHandler + completionHandler:(void (^)())completionHandler { OWSAssertIsOnMainThread(); diff --git a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m index 225fb3bf1..480673d7f 100644 --- a/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettings/AppSettingsViewController.m @@ -204,6 +204,7 @@ // TODO: Always show backup when we go to production. BOOL isBackupEnabled = [OWSBackup.sharedManager isBackupEnabled]; BOOL showBackup = isBackupEnabled; + SUPPRESS_DEADSTORE_WARNING(showBackup); #ifdef DEBUG showBackup = YES; #endif diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m index 065d8e2c6..7aff79484 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSQuotedMessageView.m @@ -331,7 +331,9 @@ NS_ASSUME_NONNULL_BEGIN OWSAssert(self.quotedTextLabel); UIColor *textColor = self.quotedTextColor; + SUPPRESS_DEADSTORE_WARNING(textColor); UIFont *font = self.quotedTextFont; + SUPPRESS_DEADSTORE_WARNING(font); NSString *text = @""; NSString *_Nullable fileTypeForSnippet = [self fileTypeForSnippet]; diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 6f3867dbb..8a1f71ab0 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -1413,13 +1413,12 @@ typedef enum : NSUInteger { UIColor *subtitleColor = [UIColor.ows_navbarTitleColor colorWithAlphaComponent:(CGFloat)0.9]; if (self.thread.isMuted) { // Show a "mute" icon before the navigation bar subtitle if this thread is muted. - [subtitleText - appendAttributedString:[[NSAttributedString alloc] - initWithString:@"\ue067 " - attributes:@{ - NSFontAttributeName : [UIFont ows_elegantIconsFont:7.f], - NSForegroundColorAttributeName : subtitleColor - }]]; + [subtitleText appendAttributedString:[[NSAttributedString alloc] + initWithString:LocalizationNotNeeded(@"\ue067 ") + attributes:@{ + NSFontAttributeName : [UIFont ows_elegantIconsFont:7.f], + NSForegroundColorAttributeName : subtitleColor + }]]; } BOOL isVerified = YES; @@ -1432,13 +1431,12 @@ typedef enum : NSUInteger { } if (isVerified) { // Show a "checkmark" icon before the navigation bar subtitle if this thread is verified. - [subtitleText - appendAttributedString:[[NSAttributedString alloc] - initWithString:@"\uf00c " - attributes:@{ - NSFontAttributeName : [UIFont ows_fontAwesomeFont:10.f], - NSForegroundColorAttributeName : subtitleColor, - }]]; + [subtitleText appendAttributedString:[[NSAttributedString alloc] + initWithString:LocalizationNotNeeded(@"\uf00c ") + attributes:@{ + NSFontAttributeName : [UIFont ows_fontAwesomeFont:10.f], + NSForegroundColorAttributeName : subtitleColor, + }]]; } if (self.userLeftGroup) { diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index 760f88c6b..f9ecd330c 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -371,7 +371,7 @@ NS_ASSUME_NONNULL_BEGIN } else { if ([thread isMuted]) { [snippetText appendAttributedString:[[NSAttributedString alloc] - initWithString:@"\ue067 " + initWithString:LocalizationNotNeeded(@"\ue067 ") attributes:@{ NSFontAttributeName : [UIFont ows_elegantIconsFont:9.f], NSForegroundColorAttributeName : diff --git a/Signal/src/ViewControllers/Registration/CodeVerificationViewController.m b/Signal/src/ViewControllers/Registration/CodeVerificationViewController.m index 11750638b..b84aaa510 100644 --- a/Signal/src/ViewControllers/Registration/CodeVerificationViewController.m +++ b/Signal/src/ViewControllers/Registration/CodeVerificationViewController.m @@ -329,7 +329,7 @@ NS_ASSUME_NONNULL_BEGIN [alert addAction:[UIAlertAction actionWithTitle:CommonStrings.dismissButton style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [_challengeTextField becomeFirstResponder]; + [self.challengeTextField becomeFirstResponder]; }]]; [self presentViewController:alert animated:YES completion:nil]; diff --git a/Signal/src/ViewControllers/ThreadSettings/FingerprintViewController.m b/Signal/src/ViewControllers/ThreadSettings/FingerprintViewController.m index f202bee29..446e8154b 100644 --- a/Signal/src/ViewControllers/ThreadSettings/FingerprintViewController.m +++ b/Signal/src/ViewControllers/ThreadSettings/FingerprintViewController.m @@ -354,7 +354,7 @@ typedef void (^CustomLayoutBlock)(void); // Show a "checkmark" if this user is verified. [labelText appendAttributedString:[[NSAttributedString alloc] - initWithString:@"\uf00c " + initWithString:LocalizationNotNeeded(@"\uf00c ") attributes:@{ NSFontAttributeName : [UIFont ows_fontAwesomeFont:self.verificationStateLabel.font.pointSize], @@ -383,7 +383,7 @@ typedef void (^CustomLayoutBlock)(void); // Show a "checkmark" if this user is not verified. [buttonText appendAttributedString:[[NSAttributedString alloc] - initWithString:@"\uf00c " + initWithString:LocalizationNotNeeded(@"\uf00c ") attributes:@{ NSFontAttributeName : [UIFont ows_fontAwesomeFont:self.verifyUnverifyButtonLabel.font.pointSize], diff --git a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m index 112662c78..33983ab71 100644 --- a/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m +++ b/Signal/src/ViewControllers/ThreadSettings/OWSConversationSettingsViewController.m @@ -786,7 +786,7 @@ const CGFloat kIconViewLength = 24; NSMutableAttributedString *subtitle = [NSMutableAttributedString new]; // "checkmark" [subtitle appendAttributedString:[[NSAttributedString alloc] - initWithString:@"\uf00c " + initWithString:LocalizationNotNeeded(@"\uf00c ") attributes:@{ NSFontAttributeName : [UIFont ows_fontAwesomeFont:kSubtitlePointSize], diff --git a/SignalServiceKit/src/Util/OWSAsserts.h b/SignalServiceKit/src/Util/OWSAsserts.h index 9f526abf7..db908206a 100755 --- a/SignalServiceKit/src/Util/OWSAsserts.h +++ b/SignalServiceKit/src/Util/OWSAsserts.h @@ -137,6 +137,19 @@ NS_ASSUME_NONNULL_BEGIN 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. void SwiftAssertIsOnMainThread(NSString *functionName);