On May 26, 2014, at 4:20 PM, Graham Cox <graham....@bigpond.com> wrote:
> 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). 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. The right way to do this would be something like: uint32_t length = *(uint32_t*)bytes; length = CFSwapInt32BigToHost(length); You need to be explicit about the size of integer in use (“int” has different sizes on different platforms) and you need to convert from the byte-order used in the file format (which is almost always big-endian.) —Jens _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com