1
0
Fork 0
mirror of https://codeberg.org/icewind/bitbuffer.git synced 2026-06-04 00:54:07 +02:00

fix signed reading

This commit is contained in:
Robin Appelman 2019-08-26 20:17:59 +02:00
commit c3709e57d8
2 changed files with 17 additions and 10 deletions

View file

@ -242,14 +242,8 @@ where
where
T: PrimInt + BitOrAssign + IsSigned + UncheckedPrimitiveInt,
{
let type_bit_size = size_of::<T>() * 8;
let raw = self.read_usize(position, count);
let max_signed_value = (1 << (type_bit_size - 1)) - 1;
if T::is_signed() && raw > max_signed_value {
T::zero() - T::from_unchecked(raw & max_signed_value)
} else {
T::from_unchecked(raw)
}
T::from_unchecked(raw)
}
/// Panics: