Re: EXC_BAD_ACCESS in NSData
Re: EXC_BAD_ACCESS in NSData
- Subject: Re: EXC_BAD_ACCESS in NSData
- From: Graham Cox <email@hidden>
- Date: Tue, 27 May 2014 10:48:54 +1000
On 27 May 2014, at 10:13 am, Jens Alfke <email@hidden> wrote:
> No, it’s extremely common to have a data format where a variable-length field is prefixed with its length. That looks like what this code is trying to read.
Alright, but you have to know that. I was looking at the code from a general standpoint, where its format was unknown - just a blob of data. Also, just reading the bytes blindly doesn't take into account endianness, though you and Roland do mention that.
What I prefer to do when parsing blobs of data like this is declare types that represent chunks of the format, such as a struct that matches the header (being careful about matching the padding used by the file) then cast or copy the data buffer, taking into account endianness, into that type. It makes the code a lot more readable, because you are not just reading from a arbitrary offset, but are using a named field.
--Graham
_______________________________________________
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