Switch from WordCount() to reg.size() for bitops

This avoids a potential problem when OR'ing with 0 that results in a WordCount() of 1. Integer's minimum reg[] size is 2 due to RoundupSize(), and there could be implicit assumptions for the minimum that did not surface under testing
This commit is contained in:
Jeffrey Walton 2016-11-26 00:56:02 -05:00
parent beb9df9d9e
commit ccef9149af
No known key found for this signature in database
GPG Key ID: B36AB348921B1838

View File

@ -3746,18 +3746,18 @@ Integer Integer::And(const Integer& t) const
{
return AbsoluteValue();
}
else if (WordCount() >= t.WordCount())
else if (reg.size() >= t.reg.size())
{
Integer result(t);
AndWords(result.reg, reg, t.WordCount());
AndWords(result.reg, reg, t.reg.size());
result.sign = POSITIVE;
return result;
}
else // WordCount() < t.WordCount()
else // reg.size() < t.reg.size()
{
Integer result(*this);
AndWords(result.reg, t.reg, WordCount());
AndWords(result.reg, t.reg, reg.size());
result.sign = POSITIVE;
return result;
@ -3772,18 +3772,18 @@ Integer Integer::Or(const Integer& t) const
{
return AbsoluteValue();
}
else if (WordCount() >= t.WordCount())
else if (reg.size() >= t.reg.size())
{
Integer result(*this);
OrWords(result.reg, t.reg, t.WordCount());
OrWords(result.reg, t.reg, t.reg.size());
result.sign = POSITIVE;
return result;
}
else // WordCount() < t.WordCount()
else // reg.size() < t.reg.size()
{
Integer result(t);
OrWords(result.reg, reg, WordCount());
OrWords(result.reg, reg, reg.size());
result.sign = POSITIVE;
return result;
@ -3798,18 +3798,18 @@ Integer Integer::Xor(const Integer& t) const
{
return Integer::Zero();
}
else if (WordCount() >= t.WordCount())
else if (reg.size() >= t.reg.size())
{
Integer result(*this);
XorWords(result.reg, t.reg, t.WordCount());
XorWords(result.reg, t.reg, t.reg.size());
result.sign = POSITIVE;
return result;
}
else // WordCount() < t.WordCount()
else // reg.size() < t.reg.size()
{
Integer result(t);
XorWords(result.reg, reg, WordCount());
XorWords(result.reg, reg, reg.size());
result.sign = POSITIVE;
return result;