Merge rust-bitcoin/rust-bitcoin#2410: Use `unsigned_abs` instead of manual code

dda83707a2 Use `unsigned_abs` instead of manual code (Martin Habovstiak)

Pull request description:

  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

ACKs for top commit:
  apoelstra:
    ACK dda83707a2
  tcharding:
    ACK dda83707a2

Tree-SHA512: c57bf440705c69917206aab36bbbe5b048ed52d7a96ebd055416b8a249fc3f7ba32ebff3d2251b971e7ef999ff8169ac3db8e599ab38cf0776ecc030447a9a4a
This commit is contained in:
Andrew Poelstra 2024-01-28 23:18:53 +00:00
commit 34d98356cd
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 1 additions and 1 deletions

View File

@ -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;