Boost logo

Boost :

Subject: Re: [boost] [intrusive] crash with slist push_back
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2016-05-12 16:53:44


On 10/05/2016 15:14, Arpan Sen wrote:
> #include <iostream>
> #include <boost/container/flat_map.hpp>
> #include <map>
> //#include <boost/intrusive/list.hpp>
> #include <boost/intrusive/slist.hpp>
>
> using namespace boost::intrusive;
>
> struct m : public slist_base_hook<>
> {
> int n;
> public:
> m(int k) : n(k) { }
> };
>
> int main()
> {
> boost::container::flat_map<int, slist<m, cache_last<true> > > c1;
> std::map<int, slist<m, cache_last<true> > > c2;
> m* m1 = new m(22);
> c1[1].push_back(*m1);
>
> m* tt = new m(99);
> c2[1].push_back(*tt);
> }

It's a bug in the implementation of the slist's move constructor, it
fails to initialize the internal last element cache. Please try to
change this:

    slist_impl(BOOST_RV_REF(slist_impl) x)
       : data_(::boost::move(x.priv_value_traits()))
    {
       this->priv_size_traits().set_size(size_type(0));
       node_algorithms::init_header(this->get_root_node());
       //nothrow, no need to rollback to release elements on exception
       this->swap(x);
    }

with this:

    slist_impl(BOOST_RV_REF(slist_impl) x)
       : data_(::boost::move(x.priv_value_traits()))
    {
       this->set_default_constructed_state();
       //nothrow, no need to rollback to release elements on exception
       this->swap(x);
    }

Best,

Ion


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk