From acd19c10d008b1b48a3d06dd4bdfbb548ba56842 Mon Sep 17 00:00:00 2001 From: Dave Hickin Date: Fri, 4 Mar 2016 23:51:12 +0000 Subject: [PATCH] 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 d4292d81f2391a5bb5e5747f0f6ceacec028c1e2) Number of tests planned corrected. --- src/misc/bitSet.cpp | 3 ++- testApp/misc/testBitSet.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/misc/bitSet.cpp b/src/misc/bitSet.cpp index 8bfbabb..de19ea9 100644 --- a/src/misc/bitSet.cpp +++ b/src/misc/bitSet.cpp @@ -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++) diff --git a/testApp/misc/testBitSet.cpp b/testApp/misc/testBitSet.cpp index 36fc645..6cb2a3b 100644 --- a/testApp/misc/testBitSet.cpp +++ b/testApp/misc/testBitSet.cpp @@ -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<<"# "<