Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2004-02-04 10:59:08

On Mon, 02 Feb 2004 16:34:22 -0800, Lester Gong <ljmgong_at_[hidden]>

>There is a bug in dynamic_bitset operator<<=().
>Calling operator<<=() followed by operator>>=() may shift in non-zero
>bits from the left.
>For example, this sequence of statements ...
>dynamic_bitset<> b(std::string("0110");
>b <<= 1; // gives "1100"
>b <<= 1; // gives "1000"
>b <<= 1; // gives "0000"
>b >>= 1; // gives "1000" !!
>b >>= 1; // gives "1100" !!
>b >>= 1; // gives "0110"
>Seems that some stray bits are not cleared when shifted beyond the lhs
>of the bitfield.

Yep, that was a stupid bug by me :( It was fixed a while ago, when I
added an assert in the dynamic_bitset destructor that checks the
invariants of the objects being destroyed. Unfortunately the official
dynamic_bitset has been unchanged for long time, for various reasons
(there's a more recent version in the sandbox, but that's still
outdated) and so the bug is still there.

The good news are that a major update will be uploaded in the next
days. Stay tuned :) I'll post a message to the list as soon as it will
be in the main CVS repository.

BTW, I would be really glad to know what you are using dynamic_bitset

>Attached files:
> Simple program that illustrates bug
>test_dynamic_bitset.out Output from simple test program
>dynamic_bitset.hpp.patch Patch that seems to fix the bug
>dyn_bitset_unit_tests2.cpp.patch Proposed changes to test programs
> that would catch this problem.

*Thank you* very much, Lester. That's a lot of code. I've added your
name to the source. As to the test programs I'm reluctant to add test
for specific sequences of functions (<<= followed by >>=, etc.),
unless there's a inherent logic reason. What happened here is that an
invariant was broken, and that could have caused problems whatever
(well, almost) function we called after <<=. Had you called count()
for instance, that would have failed as well.


Boost list run by bdawes at, gregod at, cpdaniel at, john at