Opened 6 years ago
#12169 new Bugs
error when copying blocks into a dynamic_bitset with size() not an integral number of bits_per_block
| Reported by: | Owned by: | jsiek | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | dynamic_bitset |
| Version: | Boost 1.61.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
Hi,
I'm trying to initialize a dynamic_bitset<unsigned char> from a vector of blocks. Here's the code:
#include <cstdlib>
#include <vector>
#include <boost/dynamic_bitset.hpp>
typedef boost::dynamic_bitset<unsigned char> BitSet;
typedef std::vector<BitSet::block_type> Block;
int main(int argc, char* argv[]) {
int nbits = atoi( argv[1] );
BitSet bits( nbits );
Block buffer;
buffer.resize( bits.num_blocks(), 0xff );
boost::from_block_range(buffer.begin(),buffer.end(), bits );
return 0;
}
If the bitset size isn't a multiple of sizeof(unsigned char) (here 8), an assert() in ~dynamic_bitset() fails and the process is aborted.
For example:
% ./a.out 1 a.out: boost-1.60.0/include/boost/dynamic_bitset/dynamic_bitset.hpp:633: ost::dynamic_bitset<Block, Allocator>::~dynamic_bitset() [with Block = unsigned char; Allocator = std::allocator<unsigned ar>]: Assertion `m_check_invariants()' failed. Aborted % ./a.out 8 % ./a.out 15 a.out: boost-1.60.0/boost/dynamic_bitset/dynamic_bitset.hpp:633: ost::dynamic_bitset<Block, Allocator>::~dynamic_bitset() [with Block = unsigned char; Allocator = std::allocator<unsigned ar>]: Assertion `m_check_invariants()' failed. Aborted % ./a.out 16 %
I see this with 1.59 & 1.60 using either g++ 4.7.2 or Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Thanks, Diab
Note:
See TracTickets
for help on using tickets.
