fix: apply sign extension when decoding int (#732)

Closes #730
This commit is contained in:
Paolo Barbolini
2024-08-30 08:20:29 -04:00
committed by GitHub
parent 291df5acc9
commit 79fb85323c
2 changed files with 21 additions and 2 deletions
+13
View File
@@ -36,6 +36,19 @@ fn test_get_u16() {
assert_eq!(0x5421, buf.get_u16_le());
}
#[test]
fn test_get_int() {
let mut buf = &b"\xd6zomg"[..];
assert_eq!(-42, buf.get_int(1));
let mut buf = &b"\xd6zomg"[..];
assert_eq!(-42, buf.get_int_le(1));
let mut buf = &b"\xfe\x1d\xc0zomg"[..];
assert_eq!(0xffffffffffc01dfeu64 as i64, buf.get_int_le(3));
let mut buf = &b"\xfe\x1d\xc0zomg"[..];
assert_eq!(0xfffffffffffe1dc0u64 as i64, buf.get_int(3));
}
#[test]
#[should_panic]
fn test_get_u16_buffer_underflow() {