Re: Crash when creating instance of class
Re: Crash when creating instance of class
- Subject: Re: Crash when creating instance of class
- From: Guy English <email@hidden>
- Date: Tue, 23 Nov 2004 14:27:43 -0500
Hi,
I think this:
> id person = (id)malloc ( sizeof(id) );
> id alias = person;
> alias->isa = AIPerson;
> [alias init];
Is going to crash anyway because you're only allocating enough space
for an object with no ivars. Once you call init AIPerson is going to
stamp all over memory that it doesn't have. I think. :) Haven't looked
at the runtime in ages and I'm not in front of my Mac.
> On Nov 23, 2004, at 9:35 AM, Jason Bell wrote:
> > Exception: EXC_BAD_ACCESS (0x0001)
> > Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000010
Nutty. :) Can we see the header for the class? The address it's
stamping on makes it look like the malloc is failing, returning NULL
then the init code goes on to write to it anyway and the first var it
tries to write to happens to be at offset 0x00000010. That's my guess
anyway. Now why the malloc is failing I dunno and why the runtime
doesn't check I dunno either. :) But looking that the header could
give us a few hints.
Take care,
Guy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden