mirror of
https://github.com/status-im/nim-stew.git
synced 2025-01-23 10:29:44 +00:00
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…
x
Reference in New Issue
Block a user