Skip to content

Failure case only works by accident #15

@jbb1003

Description

@jbb1003

I know this code is really old, but some people are still using it.

  • (void) accessTokenTicket:(OAServiceTicket )ticket didFailWithError:(NSError *) error {
    NSLog(@"access token did fail *
    *************");

    [self performSelectorOnMainThread:@selector(callDelegateOnMainThreadWithAccessTokenTicket:didFailWithError:) withObject:error waitUntilDone:[NSThread isMainThread]];
    }

  • (void) callDelegateOnMainThreadWithAccessTokenTicket:(OAServiceTicket *)ticket didFailWithError:(NSError *) error {
    [self.delegate accessTokenTicket:ticket didFailWithError:error];
    }

Notice that the call to performSelectorOnMainThread passes error in the withObject parameter. Notice that callDelegateOnMainThreadWithAccessTokenTicket expects error as the SECOND parameter.

The only reason this ever worked is because in

  • (void) accessTokenTicket:(OAServiceTicket *)ticket didFailWithError:(NSError *) error {

takes 'error' as the second parameter, so it's already in the correct register (on ARM). The regs get saved to the stack, then they get pulled out later on, and miraculously, and thankfully, the error arg is in the right place. It crashes the simulator reliably, because the x86 calling standard generally passes parameters on the stack rather than in regs so you need to be a lot luckier to get things in the right place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions