Bug 1522710 - Assert |!mod->isZero()| in bigint code where such is not entirely obvious unless you think about it. r=terpri

--HG--
extra : rebase_source : 075a2cb07b70744247bb129b24b0c2ff6418da4e
This commit is contained in:
Jeff Walden 2019-01-24 16:00:51 -08:00
parent 462bfe5e5b
commit 8ca83fbf1e

View File

@ -2347,10 +2347,15 @@ BigInt* BigInt::asIntN(JSContext* cx, HandleBigInt x, uint64_t bits) {
// Step 4: If `mod >= 2**(bits - 1)`, return `mod - 2**bits`; otherwise,
// return `mod`.
if (mod->digitLength() == CeilDiv(bits, DigitBits) &&
(mod->digit(mod->digitLength() - 1) & signBit) != 0) {
bool resultNegative = true;
return truncateAndSubFromPowerOfTwo(cx, mod, bits, resultNegative);
if (mod->digitLength() == CeilDiv(bits, DigitBits)) {
MOZ_ASSERT(!mod->isZero(),
"nonzero bits implies nonzero digit length which implies "
"nonzero overall");
if ((mod->digit(mod->digitLength() - 1) & signBit) != 0) {
bool resultNegative = true;
return truncateAndSubFromPowerOfTwo(cx, mod, bits, resultNegative);
}
}
return mod;