byte_buffer: fix string handling when the string is only a single null byte

This commit is contained in:
Matt Bilker
2018-09-22 02:20:15 +00:00
parent 1824da0237
commit a674780bdf
2 changed files with 8 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "kbinxml"
version = "0.11.2"
version = "0.11.3"
authors = ["Matt Bilker <me@mbilker.us>"]
[dependencies]

View File

@@ -18,7 +18,13 @@ pub(crate) fn strip_trailing_null_bytes<'a>(data: &'a [u8]) -> &'a [u8] {
while index > 0 && index < len && data[index] == 0x00 {
index -= 1;
}
&data[..=index]
// Handle case where the buffer is only a null byte
if index == 0 && data.len() == 1 && data[index] == 0x00 {
&[]
} else {
&data[..=index]
}
}
pub struct ByteBufferRead {