flatty icon indicating copy to clipboard operation
flatty copied to clipboard

Incorrect serialization on 32-bit platforms.

Open vanyle opened this issue 1 year ago • 0 comments

On platform where int are 32 bits, toFlatty (or fromFlatty depending on your POV) is incorrect.

fromFlatty always assumes that an int is 64 bits.

proc fromFlatty*(s: string, i: var int, x: var int) =
  x = s.readInt64(i).int
  i += 8

But toFlatty(s: var string, x: int) does not exist, so when serializing, int32 is picked, which is incorrect. This leads to a crash during deserialization.

While most computers are 64 bits nowadays, this is an issue when compiling for webassembly.

The simplest solution would be to write a toFlatty(s: var string, x: int) function that calls the correct function depending on the platform. This should have no performance cost.

vanyle avatar Jan 07 '24 16:01 vanyle