Skip to content

Commit 12a066b

Browse files
authored
DEVEX-774 Fix Infer analyzer warnings. (#860)
1 parent 86fa70c commit 12a066b

File tree

10 files changed

+81
-53
lines changed

10 files changed

+81
-53
lines changed

Branch-SDK/Branch-SDK/BNCApplication.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ + (NSDate*) firstInstallBuildDate {
101101
forService:kBranchKeychainService
102102
key:kBranchKeychainFirstBuildKey
103103
cloudAccessGroup:nil];
104-
104+
if (error) BNCLogError(@"Keychain store: %@.", error);
105105
return firstBuildDate;
106106
}
107107

@@ -136,7 +136,7 @@ + (NSDate*) firstInstallDate {
136136
forService:kBranchKeychainService
137137
key:kBranchKeychainFirstInstalldKey
138138
cloudAccessGroup:nil];
139-
139+
if (error) BNCLogError(@"Keychain store: %@.", error);
140140
return firstInstallDate;
141141
}
142142

Branch-SDK/Branch-SDK/BNCDebug.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ BOOL BNCDebuggerIsAttached() {
9393

9494
uint count = 0;
9595
Ivar *ivars = class_copyIvarList(class, &count);
96-
for (uint i = 0; i < count; ++i) {
96+
for (uint i = 0; ivars && i < count; ++i) {
9797
const char* encoding = ivar_getTypeEncoding(ivars[i]);
9898
const char* ivarName = ivar_getName(ivars[i]);
9999
const void* ivarPtr = nil;
@@ -174,7 +174,7 @@ BOOL BNCDebuggerIsAttached() {
174174

175175
count = 0;
176176
objc_property_t *properties = class_copyPropertyList(class, &count);
177-
for (int i = 0; i < count; ++i)
177+
for (int i = 0; properties && i < count; ++i)
178178
[result appendFormat:@"\tProperty name: '%s'.\n", property_getName(properties[i])];
179179
if (properties) free(properties);
180180

Branch-SDK/Branch-SDK/BNCEncodingUtils.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ + (NSData *) dataFromHexString:(NSString*)string {
439439
int highValue = -1;
440440
const uint8_t *p = (const uint8_t*) [inputData bytes];
441441
for (NSUInteger i = 0; i < inputData.length; ++i) {
442-
int value = -1;
442+
int value;
443443
if (*p >= '0' && *p <= '9')
444444
value = *p - '0';
445445
else

Branch-SDK/Branch-SDK/BNCLog.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,8 @@ BOOL BNCLogByteWrapOpenURL_Internal(NSURL *url, long maxBytes) {
428428
NSString *record = BNCLogByteWrapReadNextRecord();
429429
while (record) {
430430
NSDate *date = nil;
431-
NSString *dateString = @"";
432431
if (record.length >= 27) {
433-
dateString = [record substringWithRange:NSMakeRange(0, 27)];
432+
NSString *dateString = [record substringWithRange:NSMakeRange(0, 27)];
434433
date = [bnc_LogDateFormatter dateFromString:dateString];
435434
}
436435
if (!date || [date compare:lastDate] < 0) {

Branch-SDK/Branch-SDK/BNCSpotlightService.m

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -133,37 +133,31 @@ - (void)indexContentWithBranchUniversalObject:(BranchUniversalObject*)universalO
133133
completion(url,error);
134134
}];
135135

136-
}else {
137-
136+
} else {
137+
138+
__weak __typeof(self) weakSelf = self;
138139
[universalObject getShortUrlWithLinkProperties:linkProperty
139-
andCallback:^(NSString * _Nullable url, NSError * _Nullable error) {
140-
if (error) {
141-
if (completion) {
142-
completion([BNCPreferenceHelper preferenceHelper].userUrl, error);
143-
}
144-
}else {
145-
id attributes = [self attributeSetWithUniversalObject:universalObject
146-
thumbnail:thumbnailData
147-
url:url];
148-
NSDictionary *indexingParams = @{@"title": universalObject.title,
149-
@"url": url,
150-
@"spotlightId": url,
151-
@"userInfo": [universalObject.contentMetadata.customMetadata mutableCopy],
152-
@"keywords": [NSSet setWithArray:universalObject.keywords],
153-
@"attributeSet": attributes
154-
};
155-
[self indexUsingNSUserActivity:indexingParams];
156-
157-
// Not handling error scenarios because they are already handled upstream by the caller
158-
if (url) {
159-
if (completion) {
160-
completion(url, nil);
161-
}
162-
}
163-
}
164-
}];
140+
andCallback:^(NSString * _Nullable url, NSError * _Nullable error) {
141+
__strong __typeof(self) strongSelf = weakSelf;
142+
if (!strongSelf || !url || error) {
143+
if (completion) completion([BNCPreferenceHelper preferenceHelper].userUrl, error);
144+
return;
145+
}
146+
id attributes =
147+
[strongSelf attributeSetWithUniversalObject:universalObject thumbnail:thumbnailData url:url];
148+
NSMutableDictionary *indexingParams = [NSMutableDictionary new];
149+
indexingParams[@"title"] = universalObject.title;
150+
indexingParams[@"url"] = url;
151+
indexingParams[@"spotlightId"] = url;
152+
indexingParams[@"userInfo"] = [universalObject.contentMetadata.customMetadata mutableCopy];
153+
indexingParams[@"keywords"] = [NSSet setWithArray:universalObject.keywords];
154+
indexingParams[@"attributeSet"] = attributes;
155+
[self indexUsingNSUserActivity:indexingParams];
156+
if (completion) completion(url, nil);
157+
}
158+
];
159+
165160
}
166-
167161
}
168162

169163
- (id)attributeSetWithUniversalObject:(BranchUniversalObject*)universalObject
@@ -417,7 +411,7 @@ - (void)removeSearchableItemsWithIdentifier:(NSString * _Nonnull)identifier
417411
if (identifier == nil) {
418412
NSError *error = [NSError branchErrorWithCode:BNCSpotlightIdentifierError
419413
localizedMessage:@"Spotlight indentifier not available"];
420-
completion(error);
414+
if (completion) completion(error);
421415
return;
422416
}
423417
[self removeSearchableItemsWithIdentifiers:@[identifier] callback:^(NSError * _Nullable error) {

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ @interface Branch() <BranchDeepLinkingControllerCompletionDelegate, FABKit> {
142142
@property (assign, nonatomic) BOOL useCookieBasedMatching;
143143
@property (strong, nonatomic) NSDictionary *deepLinkDebugParams;
144144
@property (assign, nonatomic) BOOL accountForFacebookSDK;
145-
@property (assign, nonatomic) id FBSDKAppLinkUtility;
145+
@property (strong, nonatomic) id FBSDKAppLinkUtility;
146146
@property (assign, nonatomic) BOOL delayForAppleAds;
147147
@property (assign, nonatomic) BOOL searchAdsDebugMode;
148148
@property (strong, nonatomic) NSMutableArray *whiteListedSchemeList;
@@ -1569,15 +1569,15 @@ - (void)indexOnSpotlightWithBranchUniversalObject:(BranchUniversalObject*)univer
15691569

15701570
if (!universalObject) {
15711571
NSError* error = [NSError branchErrorWithCode:BNCInitError localizedMessage:@"Branch Universal Object is nil"];
1572-
completion(universalObject,nil,error);
1572+
if (completion) completion(universalObject,nil,error);
15731573
return;
15741574
} else {
15751575
[spotlightService indexWithBranchUniversalObject:universalObject
15761576
linkProperties:linkProperties
15771577
callback:^(BranchUniversalObject * _Nullable universalObject,
15781578
NSString * _Nullable url,
15791579
NSError * _Nullable error) {
1580-
completion(universalObject,url,error);
1580+
if (completion) completion(universalObject,url,error);
15811581
}];
15821582
}
15831583
}
@@ -1595,8 +1595,7 @@ - (void)indexOnSpotlightUsingSearchableItems:(NSArray<BranchUniversalObject*>* )
15951595
[spotlight indexPrivatelyWithBranchUniversalObjects:universalObjects
15961596
completion:^(NSArray<BranchUniversalObject *> * _Nullable universalObjects,
15971597
NSError * _Nullable error) {
1598-
if (completion)
1599-
completion(universalObjects,error);
1598+
if (completion) completion(universalObjects,error);
16001599
}];
16011600
}
16021601

@@ -1611,8 +1610,7 @@ - (void)removeSearchableItemWithBranchUniversalObject:(BranchUniversalObject *)u
16111610
andAlias:nil];
16121611
[spotlight removeSearchableItemsWithIdentifier:dynamicUrl
16131612
callback:^(NSError * _Nullable error) {
1614-
if (completion)
1615-
completion(error);
1613+
if (completion) completion(error);
16161614
}];
16171615
}
16181616

@@ -1969,10 +1967,12 @@ - (void)insertRequestAtFront:(BNCServerRequest *)req {
19691967
}
19701968

19711969
static inline void BNCPerformBlockOnMainThreadSync(dispatch_block_t block) {
1972-
if ([NSThread isMainThread]) {
1973-
block();
1974-
} else {
1975-
dispatch_sync(dispatch_get_main_queue(), block);
1970+
if (block) {
1971+
if ([NSThread isMainThread]) {
1972+
block();
1973+
} else {
1974+
dispatch_sync(dispatch_get_main_queue(), block);
1975+
}
19761976
}
19771977
}
19781978

Branch-SDK/Branch-SDK/BranchUniversalObject.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ - (void) removeFromSpotlightWithCallback:(void (^_Nullable)(NSError * _Nullable
608608
} else {
609609
NSError *error = [NSError branchErrorWithCode:BNCSpotlightPublicIndexError
610610
localizedMessage:@"Publically indexed cannot be removed from Spotlight"];
611-
completion(error);
611+
if (completion) completion(error);
612612
}
613613
}
614614

Branch-SDK/Branch-SDK/Networking/BNCServerInterface.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ - (void)getRequest:(NSDictionary *)params
468468

469469
[self genericHTTPRequest:request retryNumber:retryNumber callback:callback
470470
retryHandler:^NSURLRequest *(NSInteger lastRetryNumber) {
471-
return [self prepareGetRequest:params url:url key:key retryNumber:++lastRetryNumber];
471+
return [self prepareGetRequest:params url:url key:key retryNumber:lastRetryNumber+1];
472472
}];
473473
}
474474

@@ -510,7 +510,7 @@ - (void)postRequest:(NSDictionary *)post
510510
retryNumber:retryNumber
511511
callback:callback
512512
retryHandler:^ NSURLRequest *(NSInteger lastRetryNumber) {
513-
return [self preparePostRequest:extendedParams url:url key:key retryNumber:++lastRetryNumber];
513+
return [self preparePostRequest:extendedParams url:url key:key retryNumber:lastRetryNumber+1];
514514
}];
515515
}
516516

@@ -834,8 +834,7 @@ - (void)updateDeviceInfoToMutableDictionary:(NSMutableDictionary *)dict {
834834
NSString *hardwareId = [deviceInfo.hardwareId copy];
835835
NSString *hardwareIdType = [deviceInfo.hardwareIdType copy];
836836
NSNumber *isRealHardwareId = @(deviceInfo.isRealHardwareId);
837-
838-
if (hardwareId && hardwareIdType && isRealHardwareId) {
837+
if (hardwareId != nil && hardwareIdType != nil && isRealHardwareId != nil) {
839838
dict[BRANCH_REQUEST_KEY_HARDWARE_ID] = hardwareId;
840839
dict[BRANCH_REQUEST_KEY_HARDWARE_ID_TYPE] = hardwareIdType;
841840
dict[BRANCH_REQUEST_KEY_IS_HARDWARE_ID_REAL] = isRealHardwareId;

scripts/xcode-analyze-infer

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# xcode-analyze-infer - Runs the Infer code analyzer on an Xcode project.
5+
#
6+
# Run from the root directory of the project.
7+
#
8+
# Installation
9+
# ------------
10+
# brew install infer
11+
# gem install xcpretty
12+
13+
function clean_up() {
14+
set +e
15+
rm compile_commands.json
16+
rm -Rf infer-out/
17+
rm xcodebuild.log
18+
}
19+
trap clean_up EXIT
20+
21+
xcodebuild | tee xcodebuild.log
22+
xcpretty -r json-compilation-database -o compile_commands.json < xcodebuild.log > /dev/null
23+
infer run --skip-analysis-in-path Pods --clang-compilation-db-files-escaped compile_commands.json
24+
temp_file=$(mktemp)
25+
cat infer-out/bugs.txt > $temp_file
26+
$EDITOR $temp_file

scripts/xcode-nuke-clean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
# xcode-nuke-clean - Nuclear clean for an xcode project.
4+
#
5+
# EB Smith, July 2015
6+
7+
rm -Rf build
8+
rm -Rf Build
9+
rm -Rf ~/Library/Developer/Xcode/DerivedData
10+

0 commit comments

Comments
 (0)