From 648c650ae700ceba6caf8f9753e7f1a1d1e8ee04 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Thu, 10 Nov 2011 11:56:58 -0600 Subject: [PATCH] Changing return type of appendPartWithFileURL:name:error: to BOOL, according to Apple guidelines for methods that accept an NSError** parameter (Thanks, Zac Bowling) Fixing issue with potential NULL dereference in setting error pointer --- AFNetworking/AFHTTPClient.h | 4 +++- AFNetworking/AFHTTPClient.m | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index ca298da..4aeb891 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -407,9 +407,11 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete @param name The name to be associated with the specified data. This parameter must not be `nil`. @param error If an error occurs, upon return contains an `NSError` object that describes the problem. + @return `YES` if the file data was successfully appended, otherwise `NO`. + @discussion The filename and MIME type for this data in the form will be automatically generated, using `NSURLResponse` `-suggestedFilename` and `-MIMEType`, respectively. */ -- (void)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error; +- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error; /** Appends encoded data to the form data. diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index e2ac85a..65babc1 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -449,13 +449,16 @@ static inline NSString * AFMultipartFormFinalBoundary() { [self appendPartWithHeaders:mutableHeaders body:data]; } -- (void)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error { +- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error { if (![fileURL isFileURL]) { NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; [userInfo setValue:fileURL forKey:NSURLErrorFailingURLErrorKey]; [userInfo setValue:NSLocalizedString(@"Expected URL to be a file URL", nil) forKey:NSLocalizedFailureReasonErrorKey]; - *error = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo] autorelease]; - return; + if (error != NULL) { + *error = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo] autorelease]; + } + + return NO; } NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:fileURL]; @@ -466,6 +469,10 @@ static inline NSString * AFMultipartFormFinalBoundary() { if (response && !error) { [self appendPartWithFileData:data name:name fileName:[response suggestedFilename] mimeType:[response MIMEType]]; + + return YES; + } else { + return NO; } }