Re: 4 byte length storage

John Bowler <[email protected]>
Newsgroups gmane.comp.graphics.png.devel
Message-ID <CAP7U39_e7WNGPUD1K18U1KuP+z1W7HfPMHtzGM57rWMKmuoZ9w@mail.gmail.com>
On Tue, Dec 6, 2016 at 8:55 AM, Andreas Kleinert
<[email protected]> 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<CHUNK *>(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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.