Skip to content

Incorrect serialization on 32-bit platforms. #38

@vanyle

Description

@vanyle

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions