leb128: avoid shifts larger than type (#123)
This commit is contained in:
parent
b55c5a6d74
commit
9a3130eb5b
|
@ -109,6 +109,11 @@ template read7(shift: untyped) =
|
|||
if (shift div 7) >= xlen:
|
||||
return (I(0), 0'i8) # Not enough data - return 0 bytes read
|
||||
|
||||
when shift >= sizeof(I) * 8:
|
||||
# avoid shift overflows: https://github.com/nim-lang/Nim/issues/19983
|
||||
if true:
|
||||
return (I(0), -cast[int8]((shift div 7) + 1))
|
||||
|
||||
let
|
||||
b = x[shift div 7]
|
||||
valb = b and 0x7f'u8 # byte without high bit
|
||||
|
|
Loading…
Reference in New Issue