[Boost-bugs] [Boost C++ Libraries] #12169: error when copying blocks into a dynamic_bitset with size() not an integral number of bits_per_block

Subject: [Boost-bugs] [Boost C++ Libraries] #12169: error when copying blocks into a dynamic_bitset with size() not an integral number of bits_per_block
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-04-29 14:25:57


#12169: error when copying blocks into a dynamic_bitset with size() not an integral
number of bits_per_block
-------------------------------------+----------------------------
 Reporter: Diab Jerius <djerius@…> | Owner: jsiek
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: dynamic_bitset
  Version: Boost 1.61.0 | Severity: Problem
 Keywords: |
-------------------------------------+----------------------------
 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

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12169>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC