PR libstdc++/87784 fix dynamic_bitset::push_back
commit16cce9e37afa3ef5c99a29fd007a30af5dca67bd
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 30 Oct 2018 14:49:32 +0000 (30 14:49 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 30 Oct 2018 14:49:32 +0000 (30 14:49 +0000)
tree39eea78abae2ee13849342bec8b4a18828ac862b
parentef621480df88e8033db45a88b7c3df7e23a85456
PR libstdc++/87784 fix dynamic_bitset::push_back

Previously the _M_Nb member was incremented before calling
_M_unchecked_set which meant that the bit being set was out of bounds.
It either set the wrong bit in an allocated word, or accessed beyond the
end of the allocated memory in the _M_w vector. The fix for the bug is
to update the _M_Nb member after using it as an index.

As an optimisation, when a new block needs to be appended the call to
_M_unchecked_set can be avoided by appending a block with the least
significant bit already set to the desired value.

PR libstdc++/87784
* include/tr2/dynamic_bitset (dynamic_bitset::push_back): When there
are no unused bits in the last block, append a new block with the
right value so the bit doesn't need to be set. Only increment size
after setting the new bit, not before.
* testsuite/tr2/dynamic_bitset/pr87784.cc: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@265625 138bc75d-0d04-0410-961f-82ee72b054a4
libstdc++-v3/ChangeLog
libstdc++-v3/include/tr2/dynamic_bitset
libstdc++-v3/testsuite/tr2/dynamic_bitset/pr87784.cc [new file with mode: 0644]