diff options
author | Damien George <damien.p.george@gmail.com> | 2016-12-14 10:39:41 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-12-14 10:39:41 +1100 |
commit | e83f140463f2144b84e2fe4fa249ab8c8426b5e9 (patch) | |
tree | 80dabf116b82ba96080601052cf1a8d23e2309f6 /py/mpz.c | |
parent | 9112b0b62b4bd0139e0c94971fdb89dab61b1668 (diff) |
py/mpz: Remove unreachable code in mpn_or_neg functions.
Diffstat (limited to 'py/mpz.c')
-rw-r--r-- | py/mpz.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -308,9 +308,13 @@ STATIC mp_uint_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, mp_uint_t jl carryi >>= DIG_SIZE; } - if (0 != carryi) { - *idig++ = carryi; - } + // At least one of j,k must be negative so the above for-loop runs at least + // once. For carryi to be non-zero here it must be equal to 1 at the end of + // each iteration of the loop. So the accumulation of carryi must overflow + // each time, ie carryi += 0xff..ff. So carryj|carryk must be 0 in the + // DIG_MASK bits on each iteration. But considering all cases of signs of + // j,k one sees that this is not possible. + assert(carryi == 0); return mpn_remove_trailing_zeros(oidig, idig); } @@ -334,9 +338,8 @@ STATIC mp_uint_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, mp_uint_t jl carryi >>= DIG_SIZE; } - if (0 != carryi) { - *idig++ = carryi; - } + // See comment in above mpn_or_neg for why carryi must be 0. + assert(carryi == 0); return mpn_remove_trailing_zeros(oidig, idig); } |