Fix handling of empty slice in Instructions

The code would've taken one element when an empty slice was requested.

Co-authored-by: Tobin C. Harding <me@tobin.cc>
This commit is contained in:
Martin Habovštiak 2022-04-21 19:14:30 +02:00 committed by GitHub
parent e6ff754b73
commit 2c28d3b448
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -746,7 +746,10 @@ impl<'a> Instructions<'a> {
fn take_slice_or_kill(&mut self, len: usize) -> Result<&'a [u8], Error> {
if self.data.len() >= len {
let slice = &self.data.as_slice()[..len];
self.data.nth(len.max(1) - 1);
if len > 0 {
self.data.nth(len - 1);
}
Ok(slice)
} else {
self.kill();