From 0203d51ec0edd7297205f555e264983b2eada568 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 7 Jun 2015 15:32:34 +0930 Subject: [PATCH] pull_varint: fix. Adapted badly from pettycoin. Signed-off-by: Rusty Russell --- bitcoin_tx.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bitcoin_tx.c b/bitcoin_tx.c index fd3e505ef..cca1b6a6b 100644 --- a/bitcoin_tx.c +++ b/bitcoin_tx.c @@ -175,21 +175,21 @@ static u64 pull_varint(const u8 **cursor, size_t *max) p = pull(cursor, max, NULL, 2); if (!p) return 0; - ret = ((u64)p[2] << 8) + p[1]; + ret = ((u64)p[1] << 8) + p[0]; } else if (*p == 0xfe) { p = pull(cursor, max, NULL, 4); if (!p) return 0; - ret = ((u64)p[4] << 24) + ((u64)p[3] << 16) - + ((u64)p[2] << 8) + p[1]; + ret = ((u64)p[3] << 24) + ((u64)p[2] << 16) + + ((u64)p[1] << 8) + p[0]; } else { p = pull(cursor, max, NULL, 8); if (!p) return 0; - ret = ((u64)p[8] << 56) + ((u64)p[7] << 48) - + ((u64)p[6] << 40) + ((u64)p[5] << 32) - + ((u64)p[4] << 24) + ((u64)p[3] << 16) - + ((u64)p[2] << 8) + p[1]; + ret = ((u64)p[7] << 56) + ((u64)p[6] << 48) + + ((u64)p[5] << 40) + ((u64)p[4] << 32) + + ((u64)p[3] << 24) + ((u64)p[2] << 16) + + ((u64)p[1] << 8) + p[0]; } return ret; }