Skip to content

Commit

Permalink
Switch from WordCount() to reg.size() for bitops
Browse files Browse the repository at this point in the history
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
  • Loading branch information
noloader committed Nov 26, 2016
1 parent beb9df9 commit ccef914
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions integer.cpp
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

1 comment on commit ccef914

@noloader
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit covers And, Or and Xor.

Please sign in to comment.