From 6bf6c553fda8bbbc860d6f85900f263353cfa6d9 Mon Sep 17 00:00:00 2001 From: timsong-cpp Date: Sun, 19 Apr 2015 04:30:08 -0400 Subject: [PATCH] Fix bug in capacity() See http://stackoverflow.com/q/29727368/2756719; the bit-twiddling version is not equivalent to the original `return (index_size ? (index_size - ExtraPointers + extra_capacity) : index_size);`; it ends up subtracting, rather than adding, `extra_capacity`. --- include/boost/container/stable_vector.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/container/stable_vector.hpp b/include/boost/container/stable_vector.hpp index 76c9e9f..2e2e4e2 100644 --- a/include/boost/container/stable_vector.hpp +++ b/include/boost/container/stable_vector.hpp @@ -1117,7 +1117,7 @@ class stable_vector const size_type extra_capacity = (bucket_extra_capacity < node_extra_capacity) ? bucket_extra_capacity : node_extra_capacity; const size_type index_offset = - (ExtraPointers + extra_capacity) & (size_type(0u) - size_type(index_size != 0)); + (ExtraPointers - extra_capacity) & (size_type(0u) - size_type(index_size != 0)); return index_size - index_offset; }