boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
96 stars 116 forks source link

basic_string move constructor with allocator argument has incorrect allocator check #133

Closed ergpudb closed 4 years ago

ergpudb commented 4 years ago

In the basic_string move constructor with allocator argument:

basic_string(BOOST_RV_REF(basic_string) s, const allocator_type &a)

it does this check (line 715):

if(a == this->alloc()){

Shouldn't this be:

if(s.alloc() == this->alloc()){

This check should be comparing the allocator of the string being moved from (s) with this's allocator. What it is actually doing is comparing the allocator passed in (which is used to initialize this's allocator) with this's allocator. It isn't considering the allocator of the string being moved from at all. As a result swap_data can end up being called with unequal allocators (which is invalid).

The basic_string move constructor without allocator argument appears to do the correct check (line 685).

igaztanaga commented 4 years ago

Many thanks for the report, you are right.