Skip to content

Commit 156c7c5

Browse files
Kixuniltcharding
andauthored
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 <[email protected]>
1 parent b510093 commit 156c7c5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/blockdata/script.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,10 @@ impl<'a> Instructions<'a> {
746746
fn take_slice_or_kill(&mut self, len: usize) -> Result<&'a [u8], Error> {
747747
if self.data.len() >= len {
748748
let slice = &self.data.as_slice()[..len];
749-
self.data.nth(len.max(1) - 1);
749+
if len > 0 {
750+
self.data.nth(len - 1);
751+
}
752+
750753
Ok(slice)
751754
} else {
752755
self.kill();

0 commit comments

Comments
 (0)