From 2c28d3b44802d42db2e940c8e9e4c6eaaeb19c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Habov=C5=A1tiak?= Date: Thu, 21 Apr 2022 19:14:30 +0200 Subject: [PATCH] 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 --- src/blockdata/script.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index 39f00312..524e48c4 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -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();