BitSet: truncation in or_and

For "this |= set1 & set2" the result size
should be "max(this, min(set1, set2))" while
at present it is "min(set1, set2)" resulting
in truncation if the LHS is longer than the
RHS.
(cherry picked from commit d4292d81f2)

Number of tests planned corrected.
This commit is contained in:
Dave Hickin
2016-03-04 23:51:12 +00:00
parent 0c2c6a4173
commit acd19c10d0
2 changed files with 10 additions and 2 deletions

View File

@@ -279,7 +279,8 @@ namespace epics { namespace pvData {
uint32 inUse = (set1.wordsInUse < set2.wordsInUse) ? set1.wordsInUse : set2.wordsInUse;
ensureCapacity(inUse);
wordsInUse = inUse;
if(inUse>wordsInUse)
wordsInUse = inUse;
// Perform logical AND on words in common
for (uint32 i = 0; i < inUse; i++)

View File

@@ -146,12 +146,19 @@ static void testOperators()
b1.or_and(b2, b3);
str = toString(b1);
testOk1(str == "{2, 128}");
b1.clear(); b1.set(1);
b2.clear();
b3.clear(); b3.set(1);
std::cout<<"# "<<toString(b3)<<" |= "<<toString(b1)<<" & "<<toString(b2)<<"\n";
b3.or_and(b1, b2);
testOk(toString(b3) == "{1}", "%s == {1}", toString(b3).c_str());
}
MAIN(testBitSet)
{
testPlan(29);
testPlan(30);
testGetSetClearFlip();
testOperators();
return testDone();