Permalink
Browse files

Fixed crash caused by error handling in -invoke:…

Yes, again.

Method signatures differ between invocations, but the last argument is always where the NSError lives. Previous implementation used '5' hard-coded as the argument for the error, but this (obviously) caused a crash when using a method signature that had the error at a different position.
Now, we examine the method signature, find out the number of arguments, subtract 1 as it's zero-based, and put the error there.
  • Loading branch information...
Owain R Hunt
Owain R Hunt committed Jun 4, 2012
1 parent 8c92042 commit 73cf1a8ffb3fc79dbda98f8a9ae40e876f2f98cb
Showing with 5 additions and 4 deletions.
  1. +5 −4 UAGithubEngine/UAGithubEngine.m
@@ -334,11 +334,12 @@ - (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType
- (void)invoke:(void (^)(id obj))invocationBlock success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
NSError __unsafe_unretained *error = nil;
- NSError __unsafe_unretained **errorPointer = &error;
+ NSError * __unsafe_unretained *errorPointer = &error;
id __unsafe_unretained result;
NSInvocation *invocation = [NSInvocation jr_invocationWithTarget:self block:invocationBlock];
- [invocation setArgument:&errorPointer atIndex:5];
+ // Method signatures differ between invocations, but the last argument is always where the NSError lives
+ [invocation setArgument:&errorPointer atIndex:[[invocation methodSignature] numberOfArguments] - 1];
[invocation invoke];
[invocation getReturnValue:&result];
@@ -356,11 +357,11 @@ - (void)invoke:(void (^)(id obj))invocationBlock booleanSuccess:(UAGithubEngineB
{
NSError __unsafe_unretained *error = nil;
- NSError __unsafe_unretained **errorPointer = &error;
+ NSError * __unsafe_unretained *errorPointer = &error;
BOOL result;
NSInvocation *invocation = [NSInvocation jr_invocationWithTarget:self block:invocationBlock];
- [invocation setArgument:&errorPointer atIndex:5];
+ [invocation setArgument:&errorPointer atIndex:[[invocation methodSignature] numberOfArguments] - 1];
[invocation invoke];
[invocation getReturnValue:&result];

0 comments on commit 73cf1a8

Please sign in to comment.