mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
fixup: decrement before indexing with last_mut
This commit is contained in:
parent
587d4ac8ef
commit
8ba5608262
2 changed files with 17 additions and 1 deletions
|
|
@ -45,7 +45,7 @@ impl<'a> WriteData<'a> {
|
|||
fn last_mut(&mut self) -> Option<&mut u8> {
|
||||
match self {
|
||||
WriteData::Vec(vec) => vec.last_mut(),
|
||||
WriteData::Slice { data, length } if *length > 0 => Some(&mut data[*length]),
|
||||
WriteData::Slice { data, length } if *length > 0 => Some(&mut data[*length - 1]),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,3 +227,19 @@ fn test_write_to_slice() {
|
|||
// 0 padded
|
||||
assert_eq!(false, read.read_bool().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_last_slice() {
|
||||
let mut data = [0; 1];
|
||||
{
|
||||
let mut stream = BitWriteStream::from_slice(&mut data[..], LittleEndian);
|
||||
|
||||
stream.write_int::<u8>(0b1000, 4).unwrap();
|
||||
stream.write_bool(true).unwrap();
|
||||
}
|
||||
|
||||
let mut read = BitReadStream::from(BitReadBuffer::new(&data[..], LittleEndian));
|
||||
|
||||
assert_eq!(0b1000, read.read_int::<u8>(4).unwrap());
|
||||
assert_eq!(true, read.read_bool().unwrap());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue