mirror of
https://github.com/mbilker/kbinxml-rs.git
synced 2026-09-09 19:15:27 -05:00
byte_buffer: fix case where length of string may be zero with no trailing null byte
This commit is contained in:
@@ -13,8 +13,13 @@ pub use error::{KbinError, KbinErrorKind, Result};
|
||||
|
||||
/// Remove trailing null bytes, used for the `String` type
|
||||
pub(crate) fn strip_trailing_null_bytes<'a>(data: &'a [u8]) -> &'a [u8] {
|
||||
let mut index = data.len() - 1;
|
||||
let len = data.len();
|
||||
|
||||
if len == 0 {
|
||||
return data;
|
||||
}
|
||||
|
||||
let mut index = len - 1;
|
||||
while index > 0 && index < len && data[index] == 0x00 {
|
||||
index -= 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user