From b3be4710aaa53429c78d03a86e9be909dca923c0 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 22 Nov 2015 22:03:18 +0200 Subject: [PATCH] py/mpz: Normalize (remove leading zeros) xor operation result. --- py/mpz.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/py/mpz.c b/py/mpz.c index e0475d60a1..2a4fb4659d 100644 --- a/py/mpz.c +++ b/py/mpz.c @@ -285,7 +285,11 @@ STATIC mp_uint_t mpn_xor(mpz_dig_t *idig, const mpz_dig_t *jdig, mp_uint_t jlen, *idig = *jdig; } - return idig - oidig; + // remove trailing zeros + for (--idig; idig >= oidig && *idig == 0; --idig) { + } + + return idig + 1 - oidig; } /* computes i = i * d1 + d2