Skip to content

Commit ec92f24

Browse files
Fix clang analyzer warnings for Firebase Auth. (#2879)
1 parent 12633ef commit ec92f24

File tree

6 files changed

+41
-32
lines changed

6 files changed

+41
-32
lines changed

Firebase/Auth/Source/Auth/FIRAuth.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,9 +1677,9 @@ - (void)scheduleAutoTokenRefreshWithDelay:(NSTimeInterval)delay retry:(BOOL)retr
16771677
@param callback Called when the user has been signed in or when an error occurred. Invoked
16781678
asynchronously on the global auth work queue in the future.
16791679
*/
1680-
- (void)completeSignInWithAccessToken:(NSString *)accessToken
1681-
accessTokenExpirationDate:(NSDate *)accessTokenExpirationDate
1682-
refreshToken:(NSString *)refreshToken
1680+
- (void)completeSignInWithAccessToken:(nullable NSString *)accessToken
1681+
accessTokenExpirationDate:(nullable NSDate *)accessTokenExpirationDate
1682+
refreshToken:(nullable NSString *)refreshToken
16831683
anonymous:(BOOL)anonymous
16841684
callback:(FIRAuthResultCallback)callback {
16851685
[FIRUser retrieveUserWithAuth:self
@@ -1800,7 +1800,7 @@ - (BOOL)updateCurrentUser:(nullable FIRUser *)user
18001800
@param outError Return value for any error which occurs.
18011801
@return @YES on success, @NO otherwise.
18021802
*/
1803-
- (BOOL)saveUser:(FIRUser *)user
1803+
- (BOOL)saveUser:(nullable FIRUser *)user
18041804
error:(NSError *_Nullable *_Nullable)outError {
18051805
BOOL success;
18061806

@@ -2014,8 +2014,8 @@ - (BOOL)useUserAccessGroup:(NSString *_Nullable)accessGroup
20142014
return YES;
20152015
}
20162016

2017-
- (FIRUser *)getStoredUserForAccessGroup:(NSString *_Nullable)accessGroup
2018-
error:(NSError *_Nullable *_Nullable)outError {
2017+
- (nullable FIRUser *)getStoredUserForAccessGroup:(NSString *_Nullable)accessGroup
2018+
error:(NSError *_Nullable *_Nullable)outError {
20192019
FIRUser *user;
20202020
if (!accessGroup) {
20212021
NSString *userKey = [NSString stringWithFormat:kUserKey, _firebaseAppName];

Firebase/Auth/Source/AuthProvider/Phone/FIRPhoneAuthProvider.m

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ - (void)verifyClientAndSendVerificationCodeToPhoneNumber:(NSString *)phoneNumber
271271
callback(nil, error);
272272
return;
273273
}
274-
FIRSendVerificationCodeRequest *request;
274+
FIRSendVerificationCodeRequest * _Nullable request;
275275
if (appCredential) {
276276
request =
277277
[[FIRSendVerificationCodeRequest alloc]
@@ -287,28 +287,30 @@ - (void)verifyClientAndSendVerificationCodeToPhoneNumber:(NSString *)phoneNumber
287287
reCAPTCHAToken:reCAPTCHAToken
288288
requestConfiguration:self->_auth.requestConfiguration];
289289
}
290-
[FIRAuthBackend sendVerificationCode:request
291-
callback:^(FIRSendVerificationCodeResponse *_Nullable response,
292-
NSError *_Nullable error) {
293-
if (error) {
294-
if (error.code == FIRAuthErrorCodeInvalidAppCredential) {
295-
if (retryOnInvalidAppCredential) {
296-
[self->_auth.appCredentialManager clearCredential];
297-
[self verifyClientAndSendVerificationCodeToPhoneNumber:phoneNumber
298-
retryOnInvalidAppCredential:NO
299-
UIDelegate:UIDelegate
300-
callback:callback];
290+
if (request) {
291+
[FIRAuthBackend sendVerificationCode:request
292+
callback:^(FIRSendVerificationCodeResponse *_Nullable response,
293+
NSError *_Nullable error) {
294+
if (error) {
295+
if (error.code == FIRAuthErrorCodeInvalidAppCredential) {
296+
if (retryOnInvalidAppCredential) {
297+
[self->_auth.appCredentialManager clearCredential];
298+
[self verifyClientAndSendVerificationCodeToPhoneNumber:phoneNumber
299+
retryOnInvalidAppCredential:NO
300+
UIDelegate:UIDelegate
301+
callback:callback];
302+
return;
303+
}
304+
callback(nil, [FIRAuthErrorUtils unexpectedResponseWithDeserializedResponse:nil
305+
underlyingError:error]);
301306
return;
302307
}
303-
callback(nil, [FIRAuthErrorUtils unexpectedResponseWithDeserializedResponse:nil
304-
underlyingError:error]);
308+
callback(nil, error);
305309
return;
306310
}
307-
callback(nil, error);
308-
return;
309-
}
310-
callback(response.verificationID, nil);
311-
}];
311+
callback(response.verificationID, nil);
312+
}];
313+
}
312314
}];
313315
}
314316

@@ -436,7 +438,9 @@ - (void)reCAPTCHAURLWithEventID:(NSString *)eventID completion:(FIRReCAPTCHAURLC
436438
NSURLComponents *components = [[NSURLComponents alloc] initWithString:
437439
[NSString stringWithFormat:kReCAPTCHAURLStringFormat, authDomain]];
438440
[components setQueryItems:queryItems];
439-
completion([components URL], nil);
441+
if (completion) {
442+
completion([components URL], nil);
443+
}
440444
}];
441445
}
442446

Firebase/Auth/Source/Public/FIRAuth.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,8 @@ DEPRECATED_MSG_ATTRIBUTE("Please use signInWithCredential:completion: for Object
818818
/** @fn getStoredUserForAccessGroup:error:
819819
@brief Get the stored user in the given accessGroup.
820820
*/
821-
- (FIRUser *)getStoredUserForAccessGroup:(NSString *_Nullable)accessGroup
822-
error:(NSError *_Nullable *_Nullable)outError;
821+
- (nullable FIRUser *)getStoredUserForAccessGroup:(NSString *_Nullable)accessGroup
822+
error:(NSError *_Nullable *_Nullable)outError;
823823

824824
@end
825825

Firebase/Auth/Source/Storage/FIRAuthKeychain.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ NS_ASSUME_NONNULL_BEGIN
7272
@param outError The address to store any error that occurs during the process, if not nil.
7373
@return The item of the given query. nil if not exsit.
7474
*/
75-
- (NSData *)getItemWithQuery:(NSDictionary *)query error:(NSError *_Nullable *_Nullable)outError;
75+
- (nullable NSData *)getItemWithQuery:(NSDictionary *)query
76+
error:(NSError *_Nullable *_Nullable)outError;
7677

7778
/** @fn setItem:withQuery:error:
7879
@brief Set the item into keychain with given query.

Firebase/Auth/Source/Storage/FIRAuthKeychain.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ - (BOOL)removeDataForKey:(NSString *)key error:(NSError **_Nullable)error {
119119

120120
#pragma mark - Private methods for non-sharing keychain operations
121121

122-
- (NSData *)itemWithQuery:(NSDictionary *)query error:(NSError **_Nullable)error {
122+
- (nullable NSData *)itemWithQuery:(NSDictionary *)query error:(NSError **_Nullable)error {
123123
NSMutableDictionary *returningQuery = [query mutableCopy];
124124
returningQuery[(__bridge id)kSecReturnData] = @YES;
125125
returningQuery[(__bridge id)kSecReturnAttributes] = @YES;
@@ -233,7 +233,8 @@ - (NSDictionary *)legacyGenericPasswordQueryWithKey:(NSString *)key {
233233

234234
#pragma mark - Private methods for shared keychain operations
235235

236-
- (NSData *)getItemWithQuery:(NSDictionary *)query error:(NSError *_Nullable *_Nullable)outError {
236+
- (nullable NSData *)getItemWithQuery:(NSDictionary *)query
237+
error:(NSError *_Nullable *_Nullable)outError {
237238
NSMutableDictionary *mutableQuery = [query mutableCopy];
238239

239240
mutableQuery[(__bridge id)kSecReturnData] = @YES;

Firebase/Auth/Source/Utilities/FIRAuthErrorUtils.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,10 @@ + (NSError *)errorWithCode:(FIRAuthInternalErrorCode)code
745745
if (isPublic) {
746746
// This is a public error. Return it as a public error and add a description.
747747
NSInteger errorCode = code & ~FIRAuthPublicErrorCodeFlag;
748-
NSMutableDictionary *errorUserInfo = [NSMutableDictionary dictionaryWithDictionary:userInfo];
748+
NSMutableDictionary *errorUserInfo = [NSMutableDictionary dictionary];
749+
if (userInfo) {
750+
[errorUserInfo addEntriesFromDictionary:userInfo];
751+
}
749752
if (!errorUserInfo[NSLocalizedDescriptionKey]) {
750753
errorUserInfo[NSLocalizedDescriptionKey] = FIRAuthErrorDescription(errorCode);
751754
}

0 commit comments

Comments
 (0)