EXC_BAD_ACCESS in NSData
EXC_BAD_ACCESS in NSData
- Subject: EXC_BAD_ACCESS in NSData
- From: Pax <email@hidden>
- Date: Mon, 26 May 2014 14:02:04 +0100
I'm utterly perplexed by this problem because I thought that I'd been so careful in ensuring that my data can be read safely with no problems.
This is my snippet of code:
[datastream getBytes:&bytes range:NSMakeRange(positionCounter, datasize)]; // Length of packet content
positionCounter+= datasize;
datasize = (unsigned int)bytes; //This is the length of the data indicated in the data structure from the capture.
if (positionCounter+datasize>[datastream length])
{
NSLog(@"Error - Bad size in datastream.");
datasize = [datastream length]-positionCounter-1; //the minus one was just put there to ensure that we really are going to read a little less data than we have available.
NSLog(@"length %lu, position %lu, datasize %lu, pos+size %lu",[datastream length],positionCounter,datasize,positionCounter+datasize); // the result of this is length 18591, position 2974, datasize 15616, pos+size 18590
}
[datastream getBytes:&bytes range:NSMakeRange(positionCounter, datasize)]; // Packet content
When this gets run, I get EXC_BAD_ACCESS code = 2 here. I'm demonstrably reading less data than the file contains, and I've been able to read through the file successfully up to this point. Please could someone suggest to me what might be going wrong here?
_______________________________________________
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