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
This commit is contained in:
Mattt Thompson 2011-11-10 11:56:58 -06:00
parent bb4aaa68fa
commit 648c650ae7
2 changed files with 13 additions and 4 deletions

View file

@ -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 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. @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. @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. Appends encoded data to the form data.

View file

@ -449,13 +449,16 @@ static inline NSString * AFMultipartFormFinalBoundary() {
[self appendPartWithHeaders:mutableHeaders body:data]; [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]) { if (![fileURL isFileURL]) {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
[userInfo setValue:fileURL forKey:NSURLErrorFailingURLErrorKey]; [userInfo setValue:fileURL forKey:NSURLErrorFailingURLErrorKey];
[userInfo setValue:NSLocalizedString(@"Expected URL to be a file URL", nil) forKey:NSLocalizedFailureReasonErrorKey]; [userInfo setValue:NSLocalizedString(@"Expected URL to be a file URL", nil) forKey:NSLocalizedFailureReasonErrorKey];
*error = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo] autorelease]; if (error != NULL) {
return; *error = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo] autorelease];
}
return NO;
} }
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:fileURL]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:fileURL];
@ -466,6 +469,10 @@ static inline NSString * AFMultipartFormFinalBoundary() {
if (response && !error) { if (response && !error) {
[self appendPartWithFileData:data name:name fileName:[response suggestedFilename] mimeType:[response MIMEType]]; [self appendPartWithFileData:data name:name fileName:[response suggestedFilename] mimeType:[response MIMEType]];
return YES;
} else {
return NO;
} }
} }