1

I would like to play around with EXC_BAD_ACCESS to learn to debug it, and found that it is rather difficult to create such a situation.

I would like to see the use of "Enabeling Zombie Objects" in Scheme

Where is it when you need it?

Not even this work - setting build setting to not using ARC:

myobj *m = [[myobj alloc] init];
[m release];
[m dealloc];

 m = nil;
[m hello];

Some of the very good suggestions like:

int * array = (void *)0xDEADBEEF;
    array[2] = 10;

It only make Xcode stop saying bad access at the line, I need worse :-)

I have seen situations where it ends up in main.m where it is the hardest to debug. Can you create one?

2

3 Answers 3

3

Try this

- (void) badAccess
{
    void (*nullFunction)() = NULL;
    nullFunction();
}
0

EXC_BAD_ACCESS means you're trying to access memory that you're not allowed to. That being the case, almost any setting of a pointer to an arbitrary address will raise this exception double-quick:

NSString * s = (__bridge id)(void *)0x8BADF00D;
[s uppercaseString];

Or

int * array = (void *)0xDEADBEEF;
array[2] = 10; 

I'm not sure how helpful this will be for practicing; I think it'll be way too obvious what's going on, but that's how you do it if you want to.

0

I think you could use strcmp(0, "");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.