DarioSamo / libgens-sonicglvl

Level Editor for the PC version of Sonic Generations
http://forums.sonicretro.org/index.php?showtopic=27333
Other
54 stars 24 forks source link

Usage of size_t for file addresses by LibGens #2

Open NotKit opened 8 years ago

NotKit commented 8 years ago

LibGens and namely LibGens::File class use _sizet type for reading/writing addresses stored in files. _sizet is unsigned int on 32-bit systems, but for 64-bit ones it is unsigned long int (8 bytes). This breaks code portability. readInt32A and readInt32BEA, as well as corresponding write functions, are supposed to always read 32-bit value even on 64-bit systems for file formats compatibility. There are different ways to approach this, and I'm not sure what would be the correct one.

  1. Replace _sizet by unsigned int where needed. This should be save as long as it's used for file offsets, and not for memory pointers, but might require a lot of code edits.
  2. Introduce a custom typedef for unsigned int. The rest is the same as first.
  3. Modify read functions to ensure they always read 4 bytes and then properly put them into 8 bytes size_t variables, as well as do the opposite to write. The easiest, but seems like a hack to me.