Closed semihbkgr closed 9 months ago
This is working as intended. All varints are decoded as u64/i64 first, then cast down to a more narrow type if necessary. This will consume as many bytes of input as needed to consume the whole varint. If you want to always get the correct result, just decode as u64 or i64 and check the range yourself.
I got it 👍. Thank you. So, to detect overflow, decode into a larger integer type, then manually cast to the desired integer type.
The decoded integer value is evaluated with respect to only the first bytes that can fit within the integer size in case of overflow.
e.g: