mirror of
https://github.com/edwinb/Idris2-boot.git
synced 2024-09-11 16:05:51 +03:00
Fix unmarshalling of Integer values in TTC
Switch (un)marshalling of Integer values to Bits8 instead of Int. Previously, in `fromLimbs`, the read values arrived as a list of (32-bit) Ints. If any of the limbs had its MSB set, it would be interpreted as a negative number and corrupt the result. This commit fixes this by using a `List Bits8` instead, which has an explicit (and direct) mapping to Bytes in the Buffer, where it's eventually stored. This way no awkard casts need to happen.
This commit is contained in:
parent
735395f403
commit
17b01b807e
@ -383,17 +383,16 @@ count : List.Elem x xs -> Int
|
||||
count Here = 0
|
||||
count (There p) = 1 + count p
|
||||
|
||||
toLimbs : Integer -> List Int
|
||||
toLimbs : Integer -> List Bits8
|
||||
toLimbs x
|
||||
= if x == 0
|
||||
then []
|
||||
else if x == -1 then [-1]
|
||||
else fromInteger (prim__andBigInt x 0xffffffff) ::
|
||||
toLimbs (prim__ashrBigInt x 32)
|
||||
else fromInteger (prim__andBigInt x 0xff) ::
|
||||
toLimbs (prim__ashrBigInt x 8)
|
||||
|
||||
fromLimbs : List Int -> Integer
|
||||
fromLimbs : List Bits8 -> Integer
|
||||
fromLimbs [] = 0
|
||||
fromLimbs (x :: xs) = cast x + prim__shlBigInt (fromLimbs xs) 32
|
||||
fromLimbs (x :: xs) = prim__zextB8_BigInt x + prim__shlBigInt (fromLimbs xs) 8
|
||||
|
||||
export
|
||||
TTC Integer where
|
||||
|
Loading…
Reference in New Issue
Block a user