Skip to content

Commit

Permalink
Fix static analyzer warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisballinger committed Jul 8, 2018
1 parent 3abf10e commit c30e66e
Show file tree
Hide file tree
Showing 23 changed files with 65 additions and 88 deletions.
4 changes: 2 additions & 2 deletions ChatSecure.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3523,7 +3523,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 4T8JLQR6GR;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/iOS",
Expand Down Expand Up @@ -3561,7 +3561,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 4T8JLQR6GR;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/iOS",
Expand Down
4 changes: 3 additions & 1 deletion ChatSecure/Classes/Controllers/FileTransferManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,9 @@ public class FileTransferManager: NSObject, OTRServerCapabilitiesDelegate {
}
mediaItem.parentObjectKey = message.messageKey
mediaItem.parentObjectCollection = message.messageCollection
let newPath = OTRMediaFileManager.path(for: mediaItem, buddyUniqueId: thread.threadIdentifier)
guard let newPath = OTRMediaFileManager.path(for: mediaItem, buddyUniqueId: thread.threadIdentifier) else {
return
}
self.connection.readWrite { transaction in
message.save(with: transaction)
mediaItem.save(with: transaction)
Expand Down
2 changes: 1 addition & 1 deletion ChatSecure/Classes/Controllers/OTRAttachmentPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
finalImage = originalImage;
}

if ([self.delegate respondsToSelector:@selector(attachmentPicker:gotPhoto:withInfo:)]) {
if (finalImage && [self.delegate respondsToSelector:@selector(attachmentPicker:gotPhoto:withInfo:)]) {
[self.delegate attachmentPicker:self gotPhoto:finalImage withInfo:info];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@property (nonatomic, strong, readonly) OTRAudioItem *currentAudioItem;
@property (nonatomic, weak, readonly) OTRAudioControlsView *currentAudioControlsView;

- (void)playAudioItem:(OTRAudioItem *)audioItem buddyUniqueId:(NSString *)buddyUniqueId error:(NSError **)error;
- (BOOL)playAudioItem:(OTRAudioItem *)audioItem buddyUniqueId:(NSString *)buddyUniqueId error:(NSError **)error;

- (void)attachAudioControlsView:(OTRAudioControlsView *)audioControlsView;

Expand Down
9 changes: 5 additions & 4 deletions ChatSecure/Classes/Controllers/OTRAudioPlaybackController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ - (void)updateTimeLabel
[self.currentAudioControlsView setTime:currentTime];
}

- (void)playURL:(NSURL *)url error:(NSError **)error;
- (BOOL)playURL:(NSURL *)url error:(NSError **)error;
{
AVURLAsset *asset = [AVURLAsset assetWithURL:url];
self.duration = CMTimeGetSeconds(asset.duration);
self.currentAudioControlsView.playPuaseProgressView.status = OTRPlayPauseProgressViewStatusPause;
error = nil;
[self.audioSessionManager playAudioWithURL:url error:error];
BOOL result = [self.audioSessionManager playAudioWithURL:url error:error];

self.currentAudioControlsView.playPuaseProgressView.status = OTRPlayPauseProgressViewStatusPause;
[self.currentAudioControlsView setTime:0];

[self startLabelTimer];
return result;
}

- (void)startLabelTimer
Expand Down Expand Up @@ -93,13 +94,13 @@ - (void)startAnimatingArc

#pragma - mark Public Methods

- (void)playAudioItem:(OTRAudioItem *)audioItem buddyUniqueId:(NSString *)buddyUniqueId error:(NSError *__autoreleasing *)error
- (BOOL)playAudioItem:(OTRAudioItem *)audioItem buddyUniqueId:(NSString *)buddyUniqueId error:(NSError *__autoreleasing *)error
{
NSURL *audioURL = [[OTRMediaServer sharedInstance] urlForMediaItem:audioItem buddyUniqueId:buddyUniqueId];

_currentAudioItem = audioItem;

[self playURL:audioURL error:error];
return [self playURL:audioURL error:error];
}

- (void)attachAudioControlsView:(OTRAudioControlsView *)audioControlsView
Expand Down
4 changes: 2 additions & 2 deletions ChatSecure/Classes/Controllers/OTRAudioSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@property (nonatomic, weak) id<OTRAudioSessionManagerDelegate> delegate;

- (void)playAudioWithURL:(NSURL *)url error:(NSError **)error;
- (BOOL)playAudioWithURL:(NSURL *)url error:(NSError **)error;
- (void)pausePlaying;
- (void)resumePlaying;
- (void)stopPlaying;
Expand All @@ -34,7 +34,7 @@
- (NSURL *)currentPlayerURL;
- (BOOL)isPlaying;

- (void)recordAudioToURL:(NSURL *)url error:(NSError **)error;
- (BOOL)recordAudioToURL:(NSURL *)url error:(NSError **)error;
- (void)stopRecording;
- (NSTimeInterval)currentTimeRecordTime;
- (NSURL *)currentRecorderURL;
Expand Down
24 changes: 14 additions & 10 deletions ChatSecure/Classes/Controllers/OTRAudioSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,30 @@ - (BOOL)isPlaying
#pragma - mark Public Methods

////// Playing //////
- (void)playAudioWithURL:(NSURL *)url error:(NSError **)error
- (BOOL)playAudioWithURL:(NSURL *)url error:(NSError **)error
{
[self stopPlaying];
[self stopRecording];
error = nil;

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:error];
if (error) {
return;
return NO;
}
[[AVAudioSession sharedInstance] setMode:AVAudioSessionModeSpokenAudio error:error];
if (error) {
return;
return NO;
}

error = nil;
self.currentPlayer = [self audioPlayerWithURL:url error:error];
if (error) {
return;
return NO;
}

[self.currentPlayer play];

return YES;
}

- (void)pausePlaying
Expand Down Expand Up @@ -119,30 +121,32 @@ - (NSURL *)currentPlayerURL
}

////// Recording //////
- (void)recordAudioToURL:(NSURL *)url error:(NSError **)error
- (BOOL)recordAudioToURL:(NSURL *)url error:(NSError **)error
{
[self stopRecording];
[self stopPlaying];

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:error];
if (error) {
return;
return NO;
}
[[AVAudioSession sharedInstance] setMode:AVAudioSessionModeSpokenAudio error:error];
if (error) {
return;
return NO;
}

self.currentRecorder = [self audioRecorderWithURL:url error:error];

if (error) {
return;
return NO;
}

self.currentRecorder.meteringEnabled = YES;
self.recordDecibelTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(updateDecibelRecording:) userInfo:nil repeats:YES];

[self.currentRecorder record];

return YES;
}

- (void)stopRecording
Expand Down Expand Up @@ -179,9 +183,9 @@ - (NSURL *)currentRecorderURL

#pragma - mark Private Methods

- (void)deactivateSession:(NSError **)error
- (BOOL)deactivateSession:(NSError **)error
{
[[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:error];
return [[AVAudioSession sharedInstance] setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:error];
}

- (AVPlayer *)audioPlayerWithURL:(NSURL *)url error:(NSError **)error
Expand Down
2 changes: 1 addition & 1 deletion ChatSecure/Classes/Controllers/OTRDatabaseManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
directory:(nullable NSString*)directory
withMediaStorage:(BOOL)withMediaStorage;

- (void)setDatabasePassphrase:(NSString *)passphrase remember:(BOOL)rememeber error:(NSError *_Nullable*)error;
- (BOOL)setDatabasePassphrase:(NSString *)passphrase remember:(BOOL)rememeber error:(NSError *_Nullable*)error;


- (BOOL)hasPassphrase;
Expand Down
8 changes: 5 additions & 3 deletions ChatSecure/Classes/Controllers/OTRDatabaseManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,17 @@ + (BOOL)existsYapDatabase
return [[NSFileManager defaultManager] fileExistsAtPath:[self defaultYapDatabasePathWithName:OTRYapDatabaseName]];
}

- (void) setDatabasePassphrase:(NSString *)passphrase remember:(BOOL)rememeber error:(NSError**)error
- (BOOL) setDatabasePassphrase:(NSString *)passphrase remember:(BOOL)rememeber error:(NSError**)error
{
BOOL result = NO;
if (rememeber) {
self.inMemoryPassphrase = nil;
[SAMKeychain setPassword:passphrase forService:kOTRServiceName account:OTRYapDatabasePassphraseAccountName error:error];
result = [SAMKeychain setPassword:passphrase forService:kOTRServiceName account:OTRYapDatabasePassphraseAccountName error:error];
} else {
[SAMKeychain deletePasswordForService:kOTRServiceName account:OTRYapDatabasePassphraseAccountName];
result = [SAMKeychain deletePasswordForService:kOTRServiceName account:OTRYapDatabasePassphraseAccountName];
self.inMemoryPassphrase = passphrase;
}
return result;
}

- (BOOL)hasPassphrase
Expand Down
4 changes: 2 additions & 2 deletions ChatSecure/Classes/Controllers/OTRMediaFileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ completionQueue:(nullable dispatch_queue_t)completionQueue;
buddyUniqueId:(NSString *)buddyUniqueId
error:(NSError* __autoreleasing *)error;

+ (NSString *)pathForMediaItem:(OTRMediaItem *)mediaItem buddyUniqueId:(NSString *)buddyUniqueId;
+ (NSString *)pathForMediaItem:(OTRMediaItem *)mediaItem buddyUniqueId:(NSString *)buddyUniqueId withLeadingSlash:(BOOL)includeLeadingSlash;
+ (nullable NSString *)pathForMediaItem:(OTRMediaItem *)mediaItem buddyUniqueId:(NSString *)buddyUniqueId;
+ (nullable NSString *)pathForMediaItem:(OTRMediaItem *)mediaItem buddyUniqueId:(NSString *)buddyUniqueId withLeadingSlash:(BOOL)includeLeadingSlash;

@property (class, nonatomic, readonly) OTRMediaFileManager *shared;

Expand Down
4 changes: 2 additions & 2 deletions ChatSecure/Classes/Controllers/OTRSettingsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ - (void) populateSettings
[settingsGroups addObject:accountsGroup];

if (OTRBranding.allowsDonation) {
NSString *donateTitle = DONATE_STRING();
NSString *donateTitle = nil;
if (TransactionObserver.hasValidReceipt) {
donateTitle = [NSString stringWithFormat:@"%@", DONATE_STRING()];
} else {
donateTitle = [NSString stringWithFormat:@"%@ 🆕", DONATE_STRING()];
donateTitle = [NSString stringWithFormat:@"%@ 🎁", DONATE_STRING()];
}
OTRDonateSetting *donateSetting = [[OTRDonateSetting alloc] initWithTitle:donateTitle description:nil];
//donateSetting.imageName = @"29-heart.png";
Expand Down
3 changes: 3 additions & 0 deletions ChatSecure/Classes/Controllers/XMPP/OTRServerCapabilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ - (void)handleDiscoverServicesQueryIQ:(XMPPIQ *)iq withInfo:(XMPPBasicTrackingIn
xmlns:XMPPDiscoverItemsNamespace];

NSArray<NSXMLElement*> *items = [query elementsForName:@"item"];
if (!items) {
items = @[];
}
self.discoveredServices = [items copy];
[self->multicastDelegate serverCapabilities:self didDiscoverServices:items];

Expand Down
19 changes: 8 additions & 11 deletions ChatSecure/Classes/Controllers/XMPP/OTRXMPPManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,6 @@ - (void)teardownStream
[_messageStatusModule deactivate];
[_omemoModule deactivate];
[_serverCheck deactivate];
_serverCheck = nil;
_fileTransferManager = nil;

[_xmppStream disconnect];
}
Expand Down Expand Up @@ -405,7 +403,7 @@ - (NSString *)accountDomainWithError:(id)error;
- (void)didRegisterNewAccountWithStream:(XMPPStream *)stream
{
self.isRegisteringNewAccount = NO;
[self authenticateWithStream:stream];
[self authenticateWithStream:stream error:nil];
}

- (void)failedToRegisterNewAccount:(NSError *)error
Expand All @@ -414,15 +412,15 @@ - (void)failedToRegisterNewAccount:(NSError *)error
[self failedToConnect:error];
}

- (void)authenticateWithStream:(XMPPStream *)stream {
NSError * error = nil;
BOOL status = YES;
- (BOOL)authenticateWithStream:(XMPPStream *)stream error:(NSError**)error {
BOOL status = NO;
if ([stream supportsXOAuth2GoogleAuthentication] && self.account.accountType == OTRAccountTypeGoogleTalk) {
status = [stream authenticateWithGoogleAccessToken:self.account.password error:&error];
status = [stream authenticateWithGoogleAccessToken:self.account.password error:error];
}
else {
status = [stream authenticateWithPassword:self.account.password error:&error];
status = [stream authenticateWithPassword:self.account.password error:error];
}
return status;
}

///////////////////////////////
Expand All @@ -449,8 +447,7 @@ - (BOOL)startConnection
}
self.xmppStream.myJID = jid;
if (![self.xmppStream isDisconnected]) {
[self authenticateWithStream:self.xmppStream];
return YES;
return [self authenticateWithStream:self.xmppStream error:nil];
}

//
Expand Down Expand Up @@ -807,7 +804,7 @@ - (void)xmppStreamDidConnect:(XMPPStream *)sender
[self continueRegisteringNewAccount];
}
else{
[self authenticateWithStream:sender];
[self authenticateWithStream:sender error:nil];
}

self.loginStatus = OTRLoginStatusAuthenticating;
Expand Down
2 changes: 1 addition & 1 deletion ChatSecure/Classes/Controllers/XMPP/OTRXMPPTorManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ - (NSString *)accountDomainWithError:(NSError**)error;
domainString = jid.domain;
}

if (!domainString.length) {
if (!domainString.length && error) {
*error = [NSError errorWithDomain:OTRXMPPErrorDomain code:OTRXMPPErrorCodeDomainError userInfo:@{NSLocalizedDescriptionKey:@"Tor accounts require a valid domain"}];
}

Expand Down
3 changes: 0 additions & 3 deletions ChatSecure/Classes/Model/OTRToastOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ - (void)addInteractionResponderWithType:(int)type
automaticallyDismiss:(BOOL)automaticallyDismiss
block:(void (^)(int interactionType))block
{
if (!block) {
block = ^void(int interactionType) { };
}
/*
CRToastInteractionResponder *interactionResponder = [CRToastInteractionResponder interactionResponderWithInteractionType:type automaticallyDismiss:automaticallyDismiss block:block];
Expand Down
4 changes: 3 additions & 1 deletion ChatSecure/Classes/Model/Yap Storage/OTRMediaItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ + (instancetype) incomingItemWithFilename:(NSString*)filename
} else {
mediaClass = [OTRFileItem class];
}

if (mediaClass) {
mediaItem = [[mediaClass alloc] initWithFilename:filename mimeType:mimeType isIncoming:YES];
} else {
// satisfying the static analyzer
mediaItem = [[OTRFileItem alloc] initWithFilename:filename mimeType:mimeType isIncoming:YES];
}
return mediaItem;
}
Expand Down
5 changes: 2 additions & 3 deletions ChatSecure/Classes/Utilities/OTRColors.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ +(UIColor *)colorWithStatus:(OTRThreadStatus)status
if (!OTRBranding.showsColorForStatus) {
return [UIColor clearColor];
}
UIColor *color = [UIColor clearColor];
UIColor *color = nil;
switch(status)
{
case OTRThreadStatusUnknown:
case OTRThreadStatusOffline:
//color = [UIColor colorWithRed: 0.763 green: 0.763 blue: 0.763 alpha: 1];
return [UIColor clearColor];
color = [UIColor clearColor];
break;
case OTRThreadStatusAway:
color = [UIColor colorWithRed: 0.901 green: 0.527 blue: 0.23 alpha: 1];
Expand Down
16 changes: 4 additions & 12 deletions ChatSecure/Classes/Utilities/OTRUtilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,28 +124,20 @@ +(NSArray *)cipherSuites

//GEt number of Supported Ciphers
status = SSLGetNumberSupportedCiphers(sslContext, &numCiphers);
//DDLogVerbose(@"SSLGetNumberSupportedCiphers result %d, count %d",(int)status, (int)numCiphers);
DDLogVerbose(@"SSLGetNumberSupportedCiphers result %d, count %d",(int)status, (int)numCiphers);
SSLCipherSuite ciphers[numCiphers];

//Get list of Supported Ciphers
status = SSLGetSupportedCiphers(sslContext, ciphers, &numCiphers);
//DDLogVerbose(@"SSLGetSupportedCiphers result %d",(int)status);
DDLogVerbose(@"SSLGetSupportedCiphers result %d",(int)status);


//NSMutableArray * discardedCiphers = [NSMutableArray array];
for (int index = 0; index < numCiphers; index++) {
if ([self useCipher:ciphers[index]]) {
NSNumber * cipher = [NSNumber numberWithUnsignedShort: ciphers[index]];
[cipherSuitesArray addObject:cipher];
}/**
* Used to detect discarded ciphers
else {
NSNumber * cipher = [NSNumber numberWithUnsignedShort: ciphers[index]];
DDLogVerbose(@"Hex value is 0x%02x", (unsigned int) ciphers[index]);
[discardedCiphers addObject:cipher];
}*/
}
}
CFRelease(sslContext);

return cipherSuitesArray;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ - (void)viewDidLoad

-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self refreshData];

[self.tableView reloadData];
Expand Down
Loading

0 comments on commit c30e66e

Please sign in to comment.