diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index 2651325d..888119d0 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -529,14 +529,17 @@ impl Script { // Write any pushdata if data_len > 0 { f.write_str(" ")?; - if index + data_len <= script.len() { - for ch in &script[index..index + data_len] { + match index.checked_add(data_len) { + Some(end) if end <= script.len() => { + for ch in &script[index..end] { write!(f, "{:02x}", ch)?; - } - index += data_len; - } else { - f.write_str("")?; - break; + } + index = end; + }, + _ => { + f.write_str("")?; + break; + }, } } }