binary icon indicating copy to clipboard operation
binary copied to clipboard

Consider using Int64 throughout the API

Open kolmodin opened this issue 11 years ago • 3 comments

We use Int in a lot of places, but Haskell only guarantees 29 bits, and 28 bits of positive integers, or referring up to 256MB. We should consider using Int64 instead of relying on having >28bits.

kolmodin avatar Apr 16 '14 07:04 kolmodin

I think it's safe to assume 32-bits. All Haskell compilers use that. ;)

tibbe avatar Apr 16 '14 08:04 tibbe

Wops, Haskell guarantees 30 bits, so 29bits of positive integers or 512MB. There are several haskell compilers and interpreters, and I'm not sure all of them use 32bits. In practice though, I think most people use GHC - meaning 32bits. We also only do testing with GHC.

This request came from Henning Thielemann wishing for skip64.

To be fair, we already do plenty of assumptions about Int sizes. The binary instance of Int always writes a Int as if it was Int64 but will on a 32bit machine convert that into 32bits when it's decoded. https://github.com/kolmodin/binary/blob/master/src/Data/Binary/Class.hs#L181

kolmodin avatar Apr 16 '14 09:04 kolmodin

I do not have a concrete misbehavior of the 'binary' package, but I am concerned in general that some functions use Int and others use Int64. There is always an architecture where conversion between Int and Int32 or Int64 may overflow. Maybe it is even possible to use such overflows for hacker attacks. Thus it is certainly a good idea to use one integer type consistently.

amigalemming avatar Apr 16 '14 19:04 amigalemming