]> git.ipfire.org Git - thirdparty/gcc.git/commit
PR libstdc++/87784 fix dynamic_bitset::push_back
authorJonathan Wakely <jwakely@redhat.com>
Tue, 30 Oct 2018 14:49:32 +0000 (14:49 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 30 Oct 2018 14:49:32 +0000 (14:49 +0000)
commitc397f267f1d0e8ea286904bc5543829b558e154f
tree39eea78abae2ee13849342bec8b4a18828ac862b
parent47abbc3196ebf5829e8552d8824665af4c8a5c6f
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.

From-SVN: r265625
libstdc++-v3/ChangeLog
libstdc++-v3/include/tr2/dynamic_bitset
libstdc++-v3/testsuite/tr2/dynamic_bitset/pr87784.cc [new file with mode: 0644]