|
Boost Users : |
Subject: Re: [Boost-users] Exception when constructing empty list in shared memory (boost::interprocess::list)
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2008-11-22 05:49:05
Roland wrote:
> Hello all (Hi Ion)
>
> Here's a small piece of code that causes an exception to be thrown (when it
> shouldn't). The environment is MSVC8 (VS2005SP1) with Boost 1.37. The code
> is an adaption of one of the samples in the interprocess documentation.
Thanks for the report. It's a bug. To fix the bug you should modify the
local copy of list.hpp. As you see there is no protection against an
empty range insertion:
template<class FwdIterator>
void priv_create_and_insert_nodes
(const_iterator pos, FwdIterator beg, FwdIterator end,
allocator_v2, std::forward_iterator_tag)
{
//Optimized allocation and construction
this->allocate_many_and_construct
(beg, std::distance(beg, end), insertion_functor(this->icont(),
pos.get()));
}
}
add a test to avoid this:
template<class FwdIterator>
void priv_create_and_insert_nodes
(const_iterator pos, FwdIterator beg, FwdIterator end, allocator_v2,
std::forward_iterator_tag)
{
if(beg != end){
//Optimized allocation and construction
this->allocate_many_and_construct
(beg, std::distance(beg, end), insertion_functor
(this->icont(), pos.get()));
}
}
Commited to SVN, revision 49871.
Regards,
Ion
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net