Skip to content

Commit

Permalink
Fixed crash caused by error handling in -invoke:…
Browse files Browse the repository at this point in the history
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 committed Jun 4, 2012
1 parent 8c92042 commit 73cf1a8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions UAGithubEngine/UAGithubEngine.m
Expand Up @@ -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];

Expand All @@ -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];

Expand Down

0 comments on commit 73cf1a8

Please sign in to comment.