Skip to content

Commit

Permalink
Enable pedantic warnings and 'treat warnings as errors'
Browse files Browse the repository at this point in the history
Fixes several issues that were out of compliance with these warnings.

Collaboration between Steven E Wright and William Denniss (see openid#62, openid#245).
  • Loading branch information
StevenEWright authored and WilliamDenniss committed Jun 8, 2018
1 parent 96b5b8b commit c4a6277
Show file tree
Hide file tree
Showing 31 changed files with 507 additions and 375 deletions.
14 changes: 14 additions & 0 deletions AppAuth.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1932,14 +1932,17 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = NO;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
Expand All @@ -1959,8 +1962,11 @@
"DEBUG=1",
"$(inherited)",
);
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_PEDANTIC = YES;
GCC_WARN_STRICT_SELECTOR_MATCH = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
Expand All @@ -1970,6 +1976,7 @@
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
WARNING_CFLAGS = "-Wno-gnu";
};
name = Debug;
};
Expand All @@ -1986,14 +1993,17 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_MISSING_PROPERTY_SYNTHESIS = NO;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
Expand All @@ -2007,8 +2017,11 @@
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_PEDANTIC = YES;
GCC_WARN_STRICT_SELECTOR_MATCH = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
Expand All @@ -2019,6 +2032,7 @@
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
WARNING_CFLAGS = "-Wno-gnu";
};
name = Release;
};
Expand Down
6 changes: 3 additions & 3 deletions Source/OIDAuthState.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ @implementation OIDAuthState
#pragma mark - Initializers

- (nonnull instancetype)init
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithAuthorizationResponse:tokenResponse:));
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithAuthorizationResponse:tokenResponse:))

/*! @brief Creates an auth state from an authorization response.
@param authorizationResponse The authorization response.
Expand Down Expand Up @@ -216,7 +216,7 @@ - (NSString *)description {
"lastAuthorizationResponse: %@, lastTokenResponse: %@, "
"lastRegistrationResponse: %@, authorizationError: %@>",
NSStringFromClass([self class]),
self,
(void *)self,
(self.isAuthorized) ? @"YES" : @"NO",
_refreshToken,
_scope,
Expand Down Expand Up @@ -457,7 +457,7 @@ - (void)performActionWithFreshTokens:(OIDAuthStateAction)action
}

// access token is expired, first refresh the token, then perform action
NSAssert(_pendingActionsSyncObject, @"_pendingActionsSyncObject cannot be nil");
NSAssert(_pendingActionsSyncObject, @"_pendingActionsSyncObject cannot be nil", @"");
@synchronized(_pendingActionsSyncObject) {
// if a token is already in the process of being refreshed, adds to pending actions
if (_pendingActions) {
Expand Down
3 changes: 2 additions & 1 deletion Source/OIDAuthorizationFlowSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
*/

/*! @brief Represents an in-flight authorization flow session.
@deprecated Please use the more generic OIDExternalUserAgentSession instead.
@deprecated Use the more generic OIDExternalUserAgentSession instead.
*/
__attribute__((deprecated("Use the more generic OIDExternalUserAgentSession instead.")))
@protocol OIDAuthorizationFlowSession <NSObject>

/*! @brief Clients should call this method with the result of the authorization code flow if it
Expand Down
4 changes: 2 additions & 2 deletions Source/OIDAuthorizationRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ - (instancetype)init
redirectURL:
responseType:
additionalParameters:)
);
)

- (instancetype)initWithConfiguration:(OIDServiceConfiguration *)configuration
clientId:(NSString *)clientID
Expand Down Expand Up @@ -308,7 +308,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
- (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p, request: %@>",
NSStringFromClass([self class]),
self,
(void *)self,
self.authorizationRequestURL];
}

Expand Down
4 changes: 2 additions & 2 deletions Source/OIDAuthorizationResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ @implementation OIDAuthorizationResponse
#pragma mark - Initializers

- (instancetype)init
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithRequest:parameters:));
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithRequest:parameters:))

- (instancetype)initWithRequest:(OIDAuthorizationRequest *)request
parameters:(NSDictionary<NSString *, NSObject<NSCopying> *> *)parameters {
Expand Down Expand Up @@ -178,7 +178,7 @@ - (NSString *)description {
"idToken: \"%@\", scope: \"%@\", additionalParameters: %@, "
"request: %@>",
NSStringFromClass([self class]),
self,
(void *)self,
_authorizationCode,
_state,
_accessToken,
Expand Down
5 changes: 5 additions & 0 deletions Source/OIDAuthorizationService.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ typedef void (^OIDRegistrationCompletion)(OIDRegistrationResponse *_Nullable reg
+ (void)discoverServiceConfigurationForDiscoveryURL:(NSURL *)discoveryURL
completion:(OIDDiscoveryCallback)completion;

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

/*! @brief Perform an authorization flow using a generic flow shim.
@param request The authorization request.
@param externalUserAgent Generic external user-agent that can present an authorization
Expand All @@ -125,6 +128,8 @@ typedef void (^OIDRegistrationCompletion)(OIDRegistrationResponse *_Nullable reg
externalUserAgent:(id<OIDExternalUserAgent>)externalUserAgent
callback:(OIDAuthorizationCallback)callback;

#pragma GCC diagnostic pop

/*! @brief Performs a token request.
@param request The token request.
@param callback The method called when the request has completed or failed.
Expand Down
20 changes: 15 additions & 5 deletions Source/OIDAuthorizationService.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@

NS_ASSUME_NONNULL_BEGIN

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

@interface OIDAuthorizationFlowSessionImplementation : NSObject<OIDExternalUserAgentSession, OIDAuthorizationFlowSession> {
// private variables
OIDAuthorizationRequest *_request;
id<OIDExternalUserAgent> _externalUserAgent;
OIDAuthorizationCallback _pendingauthorizationFlowCallback;
}

#pragma GCC diagnostic pop

- (instancetype)init NS_UNAVAILABLE;

- (instancetype)initWithRequest:(OIDAuthorizationRequest *)request
Expand Down Expand Up @@ -191,8 +196,8 @@ + (void)discoverServiceConfigurationForIssuer:(NSURL *)issuerURL
NSURL *fullDiscoveryURL =
[issuerURL URLByAppendingPathComponent:kOpenIDConfigurationWellKnownPath];

return [[self class] discoverServiceConfigurationForDiscoveryURL:fullDiscoveryURL
completion:completion];
[[self class] discoverServiceConfigurationForDiscoveryURL:fullDiscoveryURL
completion:completion];
}

+ (void)discoverServiceConfigurationForDiscoveryURL:(NSURL *)discoveryURL
Expand Down Expand Up @@ -254,6 +259,9 @@ + (void)discoverServiceConfigurationForDiscoveryURL:(NSURL *)discoveryURL

#pragma mark - Authorization Endpoint

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

+ (id<OIDExternalUserAgentSession, OIDAuthorizationFlowSession>)
presentAuthorizationRequest:(OIDAuthorizationRequest *)request
externalUserAgent:(id<OIDExternalUserAgent>)externalUserAgent
Expand All @@ -264,12 +272,14 @@ + (void)discoverServiceConfigurationForDiscoveryURL:(NSURL *)discoveryURL
return flowSession;
}

#pragma GCC diagnostic pop

#pragma mark - Token Endpoint

+ (void)performTokenRequest:(OIDTokenRequest *)request callback:(OIDTokenCallback)callback {
return [[self class] performTokenRequest:request
originalAuthorizationResponse:nil
callback:callback];
[[self class] performTokenRequest:request
originalAuthorizationResponse:nil
callback:callback];
}

+ (void)performTokenRequest:(OIDTokenRequest *)request
Expand Down
2 changes: 1 addition & 1 deletion Source/OIDFieldMapping.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ @implementation OIDFieldMapping
@synthesize conversion = _conversion;

- (nonnull instancetype)init
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithName:type:conversion:));
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithName:type:conversion:))

- (instancetype)initWithName:(NSString *)name
type:(Class)type {
Expand Down
4 changes: 2 additions & 2 deletions Source/OIDRegistrationRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ - (instancetype)init
subjectType:
tokenEndpointAuthMethod:
additionalParameters:)
);
)

- (instancetype)initWithConfiguration:(OIDServiceConfiguration *)configuration
redirectURIs:(NSArray<NSURL *> *)redirectURIs
Expand Down Expand Up @@ -159,7 +159,7 @@ - (NSString *)description {
encoding:NSUTF8StringEncoding];
return [NSString stringWithFormat:@"<%@: %p, request: <URL: %@, HTTPBody: %@>>",
NSStringFromClass([self class]),
self,
(void *)self,
request.URL,
requestBody];
}
Expand Down
4 changes: 2 additions & 2 deletions Source/OIDRegistrationResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ @implementation OIDRegistrationResponse
#pragma mark - Initializers

- (nonnull instancetype)init
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithRequest:parameters:));
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithRequest:parameters:))

- (instancetype)initWithRequest:(OIDRegistrationRequest *)request
parameters:(NSDictionary<NSString *, NSObject <NSCopying> *> *)parameters {
Expand Down Expand Up @@ -159,7 +159,7 @@ - (NSString *)description {
"registrationClientURI: \"%@\", "
"additionalParameters: %@, request: %@>",
NSStringFromClass([self class]),
self,
(void *)self,
_clientID,
_clientIDIssuedAt,
_clientSecret,
Expand Down
2 changes: 1 addition & 1 deletion Source/OIDServiceConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ - (instancetype)init
OID_UNAVAILABLE_USE_INITIALIZER(@selector(
initWithAuthorizationEndpoint:
tokenEndpoint:)
);
)

- (instancetype)initWithAuthorizationEndpoint:(NSURL *)authorizationEndpoint
tokenEndpoint:(NSURL *)tokenEndpoint
Expand Down
2 changes: 1 addition & 1 deletion Source/OIDServiceDiscovery.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

@implementation OIDServiceDiscovery

- (nonnull instancetype)init OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithDictionary:error:));
- (nonnull instancetype)init OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithDictionary:error:))

- (nullable instancetype)initWithJSON:(NSString *)serviceDiscoveryJSON error:(NSError **)error {
NSData *jsonData = [serviceDiscoveryJSON dataUsingEncoding:NSUTF8StringEncoding];
Expand Down
4 changes: 2 additions & 2 deletions Source/OIDTokenRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ - (instancetype)init
refreshToken:
codeVerifier:
additionalParameters:)
);
)

- (instancetype)initWithConfiguration:(OIDServiceConfiguration *)configuration
grantType:(NSString *)grantType
Expand Down Expand Up @@ -210,7 +210,7 @@ - (NSString *)description {
[[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding];
return [NSString stringWithFormat:@"<%@: %p, request: <URL: %@, HTTPBody: %@>>",
NSStringFromClass([self class]),
self,
(void *)self,
request.URL,
requestBody];
}
Expand Down
4 changes: 2 additions & 2 deletions Source/OIDTokenResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ @implementation OIDTokenResponse
#pragma mark - Initializers

- (instancetype)init
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithRequest:parameters:));
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithRequest:parameters:))

- (instancetype)initWithRequest:(OIDTokenRequest *)request
parameters:(NSDictionary<NSString *, NSObject<NSCopying> *> *)parameters {
Expand Down Expand Up @@ -155,7 +155,7 @@ - (NSString *)description {
"tokenType: %@, idToken: \"%@\", refreshToken: \"%@\", "
"scope: \"%@\", additionalParameters: %@, request: %@>",
NSStringFromClass([self class]),
self,
(void *)self,
_accessToken,
_accessTokenExpirationDate,
_tokenType,
Expand Down
2 changes: 1 addition & 1 deletion Source/OIDURLQueryComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ - (NSURL *)URLByReplacingQueryInURL:(NSURL *)URL {
- (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p, parameters: %@>",
NSStringFromClass([self class]),
self,
(void *)self,
_parameters];
}

Expand Down
2 changes: 1 addition & 1 deletion Source/macOS/LoopbackHTTPServer/OIDLoopbackHTTPServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ typedef enum {
__weak id delegate;
NSData *peerAddress;
__weak HTTPServer *server;
NSMutableArray *requests;
NSMutableArray<HTTPServerRequest *> *requests;
NSInputStream *istream;
NSOutputStream *ostream;
NSMutableData *ibuffer;
Expand Down
21 changes: 13 additions & 8 deletions Source/macOS/LoopbackHTTPServer/OIDLoopbackHTTPServer.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <netinet/in.h>
#include <unistd.h>

// We'll ignore the pointer arithmetic warnings for now.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpointer-arith"

@implementation HTTPServer

- (id)init {
Expand Down Expand Up @@ -99,14 +103,12 @@ - (HTTPServer *)server {
}

- (HTTPServerRequest *)nextRequest {
NSUInteger idx, cnt = requests ? [requests count] : 0;
for (idx = 0; idx < cnt; idx++) {
id obj = [requests objectAtIndex:idx];
if ([obj response] == nil) {
return obj;
}
for (HTTPServerRequest *request in requests) {
if (![request response]) {
return request;
}
return nil;
}
return nil;
}

- (BOOL)isValid {
Expand Down Expand Up @@ -173,8 +175,9 @@ - (BOOL)processIncomingBytes {
// directly as this method is called in a loop in order to process multiple messages, and
// the delegate may choose to stop and dealloc the listener – so we need queue the messages
// and process them separately.
id myDelegate = delegate;
dispatch_async(dispatch_get_main_queue(), ^() {
[self->delegate HTTPConnection:self didReceiveRequest:request];
[myDelegate HTTPConnection:self didReceiveRequest:request];
});
} else {
[self performDefaultRequestHandling:request];
Expand Down Expand Up @@ -605,3 +608,5 @@ - (BOOL)hasIPv6Socket {
}

@end

#pragma GCC diagnostic pop
Loading

0 comments on commit c4a6277

Please sign in to comment.