From dda83707a2ad88a1dfcd29c30d836432996f0521 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Sat, 27 Jan 2024 20:49:15 +0100 Subject: [PATCH] Use `unsigned_abs` instead of manual code The code originally used `if` and incorrectly casted the value into `usize` rather than `u64`. This change replaces the whole thing with `unsigned_abs`. Closes #1247 --- bitcoin/src/blockdata/script/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitcoin/src/blockdata/script/mod.rs b/bitcoin/src/blockdata/script/mod.rs index d79a58fd..6db21811 100644 --- a/bitcoin/src/blockdata/script/mod.rs +++ b/bitcoin/src/blockdata/script/mod.rs @@ -135,7 +135,7 @@ pub fn write_scriptint(out: &mut [u8; 8], n: i64) -> usize { let neg = n < 0; - let mut abs = if neg { -n } else { n } as usize; + let mut abs = n.unsigned_abs(); while abs > 0xFF { out[len] = (abs & 0xFF) as u8; len += 1;