Fix get_int if nbytes is zero (#806)

This commit is contained in:
Paolo Barbolini
2025-11-21 11:14:40 +01:00
committed by GitHub
parent a7952fb447
commit acd1e0ffb8
2 changed files with 25 additions and 9 deletions
+7 -2
View File
@@ -86,8 +86,13 @@ macro_rules! buf_get_impl {
// https://en.wikipedia.org/wiki/Sign_extension
fn sign_extend(val: u64, nbytes: usize) -> i64 {
let shift = (8 - nbytes) * 8;
(val << shift) as i64 >> shift
if nbytes == 0 {
// avoid `val << 64` panic
0
} else {
let shift = (8 - nbytes) * 8;
(val << shift) as i64 >> shift
}
}
/// Read bytes from a buffer.