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

'assert' check bounds when reading, fix issue with missing null termination for strings

This commit is contained in:
Robin Appelman 2019-07-22 18:37:38 +02:00
commit 00e4efec86
3 changed files with 59 additions and 7 deletions

View file

@ -253,6 +253,30 @@ fn test_read_str_be() {
);
}
#[test]
fn test_read_str_no_null_termination_le() {
let bytes = vec![
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64,
];
let buffer = BitBuffer::new(bytes, LittleEndian);
assert_eq!(
buffer.read_string(0, None).unwrap(),
"Hello world".to_owned()
);
}
#[test]
fn test_read_str_no_null_termination_be() {
let bytes = vec![
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64,
];
let buffer = BitBuffer::new(bytes, BigEndian);
assert_eq!(
buffer.read_string(0, None).unwrap(),
"Hello world".to_owned()
);
}
#[test]
fn test_read_str_le() {
let bytes = vec![