• 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: Roland King <email@hidden>
  • Date: Mon, 26 May 2014 22:54:03 +0800

So you have

unsigned char *bytes;

and then

datasize = (unsigned int)bytes;

which sets datasize to the address of bytes cast to an unsigned integer which has nothing to do with the data in bytes at all and in some cases just truncates the address (OSX for instance)

datasize = *((unsigned int*)bytes);

is a bit closer to what you might want but is endian-unaware.


On 26 May, 2014, at 9:44 pm, Pax <email@hidden> wrote:

> Apologies - the obvious important detail, and I missed it out entirely.  I have tried both of the following with the same result:
>
>   unsigned char* databuffer = (unsigned char*)malloc(datasize);
>   [datastream getBytes:&databuffer range:NSMakeRange(positionCounter, datasize)]; // Packet content
>
> and
>
>   unsigned char* bytes;
>   [datastream getBytes:&bytes range:NSMakeRange(positionCounter, datasize)]; // Packet content
>
> Either way, I get the same result.
>
>
>
> On 26 May 2014, at 14:16, Uli Kusterer <email@hidden> wrote:
>
>> On 26 May 2014, at 06:02, Pax <email@hidden> wrote:
>>> This is my snippet of code:
>>>                  [datastream getBytes:&bytes range:NSMakeRange(positionCounter, datasize)]; // Length of packet content
>>>                  positionCounter+= datasize;
>>
>> What is bytes declared as, and what do you initialize it to?
>>
>> 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


_______________________________________________

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: Graham Cox <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>)

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