Re: EXC_BAD_ACCESS in NSData
Re: EXC_BAD_ACCESS in NSData
- Subject: Re: EXC_BAD_ACCESS in NSData
- From: Uli Kusterer <email@hidden>
- Date: Mon, 26 May 2014 17:43:12 -0700
On 26 May 2014, at 16:20, Graham Cox <email@hidden> wrote:
> On 27 May 2014, at 12:54 am, Roland King <email@hidden> wrote:
>> datasize = *((unsigned int*)bytes);
>>
>> is a bit closer to what you might want but is endian-unaware.
>
> That's just as wrong - you are using the first few bytes of the data as the length, which it certainly isn't (except for possibly a very few special cases that just so happen to have the length as the first field of the data).
It’s not a general truth, true, but from what the OP mentioned, he’s sequentially reading stuff from his big NSData:
> datasize = (unsigned int)bytes; //This is the length of the data indicated in the data structure from the capture.
So there you need to correctly cast the start of the data into a pointer to the right size of int (in general, you’d use some stable type like uint32_t instead of unsigned int for portability, though), and then de-reference it to read.
Regarding endian-swapping, that depends on the file format. If you wrote that file yourself, you don’t usually need to do any swapping.
Cheers,
-- Uli Kusterer
“The Witnesses of TeachText are everywhere...”
http://zathras.de
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden