• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: EXC_BAD_ACCESS in NSData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: EXC_BAD_ACCESS in NSData
      • From: Charles Srstka <email@hidden>
References: 
 >EXC_BAD_ACCESS in NSData (From: Pax <email@hidden>)
 >Re: EXC_BAD_ACCESS in NSData (From: Uli Kusterer <email@hidden>)
 >Re: EXC_BAD_ACCESS in NSData (From: Pax <email@hidden>)
 >Re: EXC_BAD_ACCESS in NSData (From: Roland King <email@hidden>)
 >Re: EXC_BAD_ACCESS in NSData (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: EXC_BAD_ACCESS in NSData
  • Next by Date: Re: EXC_BAD_ACCESS in NSData
  • Previous by thread: Re: EXC_BAD_ACCESS in NSData
  • Next by thread: Re: EXC_BAD_ACCESS in NSData
  • Index(es):
    • Date
    • Thread