diff --git a/src/misc/bitSet.cpp b/src/misc/bitSet.cpp index 2d34591..a2110f9 100644 --- a/src/misc/bitSet.cpp +++ b/src/misc/bitSet.cpp @@ -323,12 +323,14 @@ namespace epics { namespace pvData { SerializeHelper::writeSize(len, buffer, flusher); flusher->ensureBuffer(len); - - for (uint32 i = 0; i < n - 1; i++) + + n = len / 8; + for (uint32 i = 0; i < n; i++) buffer->putLong(words[i]); - - for (uint64 x = words[n - 1]; x != 0; x >>= 8) - buffer->putByte((int8) (x & 0xff)); + + if (n < wordsInUse) + for (uint64 x = words[wordsInUse - 1]; x != 0; x >>= 8) + buffer->putByte((int8) (x & 0xff)); } void BitSet::deserialize(ByteBuffer* buffer, DeserializableControl* control) { diff --git a/testApp/misc/testBitSet.cpp b/testApp/misc/testBitSet.cpp index 976683a..ce20d5d 100644 --- a/testApp/misc/testBitSet.cpp +++ b/testApp/misc/testBitSet.cpp @@ -7,6 +7,7 @@ /* Author: Matej Sekoranja Date: 2010.10.18 */ #include +#include #include #include #include @@ -14,7 +15,10 @@ #include #include +#include + #include +#include #include #include @@ -155,12 +159,116 @@ static void testOperators() testOk(toString(b3) == "{1}", "%s == {1}", toString(b3).c_str()); } +static void tofrostring(const BitSet& in, const char *expect, size_t elen, int byteOrder) +{ + { + std::vector buf; + serializeToVector(&in, byteOrder, buf); + + std::ostringstream astrm, estrm; + + bool match = buf.size()==elen; + if(!match) testDiag("Lengths differ %u != %u", (unsigned)buf.size(), (unsigned)elen); + for(size_t i=0, e=std::min(elen, buf.size()); i