Steps to reproduce:
Run the following program, using bytes version 1.7.1
use bytes::{BytesMut, Buf, BufMut};
fn main() {
const SOME_NEG_NUMBER: i64 = -42;
let mut buffer = BytesMut::with_capacity(8);
buffer.put_int(SOME_NEG_NUMBER, 1);
println!("buffer = {:?}", &buffer);
assert_eq!(buffer.freeze().get_int(1), SOME_NEG_NUMBER);
}
Expected outcome:
Assertion passes and program terminates successfully, due to the symmetry of the put_int and get_int calls.
Actual outcome:
Assertion fails:
buffer = b"\xd6"
thread 'main' panicked at src/main.rs:9:5:
assertion `left == right` failed
left: 214
right: -42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Additional information:
- Only happens with negative numbers; positive numbers are always OK.
- Only happens when
nbytes parameter is < 8.
- Other combos like
put_i8()/get_i8() or put_i16()/get_i16() work as intended.