MESSAGE
DATE | 2016-12-06 |
FROM | John Bowler
|
SUBJECT | Re: [Hangout-NYLXS] [png-mng-implement] 4 byte length storage
|
On Tue, Dec 6, 2016 at 8:55 AM, Andreas Kleinert wrote: > I have not really checked your code in detail, but are you sure it is not just big vs. little endian conversion...?!
That's why '13' (0x0000000D) appears as 218103808 (0x0D000000), but there are other issues in the code that are perhaps best covered by an online tutorial such as this one:
https://isocpp.org/wiki/faq/serialization
(That's C++ specific).
One issue is that the code relies on uint32_t being a four byte quantity, CHUNK is a typedef of uint32_t:
char * cur = get_index(); CHUNK * tmp = reinterpret_cast(cur);
Certainly uint32_t is required to have exactly 32 bits and therefore behave as a 32-bit value for modular arithmetic (per the ANSI C spec), however I don't know that the representation is constrained to be 4 bytes. I would be surprised if C89 (which formalized the type) had done that and so far as I can see the above code has undefined behavior.
The general rule for serialization is to either use well-defined primitives or to do it yourself; the code is not exactly difficult to write, though it can be difficult to get right sometimes ;-)
John Bowler
------------------------------------------------------------------------------ Developer Access Program for Intel Xeon Phi Processors Access to Intel Xeon Phi processor-based developer platforms. With one year of Intel Parallel Studio XE. Training and support from Colfax. Order your platform today.http://sdm.link/xeonphi _______________________________________________ png-mng-implement mailing list png-mng-implement-at-lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/png-mng-implement _______________________________________________ hangout mailing list hangout-at-nylxs.com http://www.nylxs.com/
|
|