Boost C++ Libraries: Ticket #13533: Boost vector resize causes assert(false) https://svn.boost.org/trac10/ticket/13533 <p> When using a boost vector with a custom allocator, a resize that results in memory growth in both directions causes an assert(false) in insert_value_initialized_n_proxy::copy_n_and_update(). The code in question is contained in boost/containers/detail/advanced_insert_int.hpp. </p> <p> I have attached a test case that results in an assert. The test case uses a custom allocator, but the problem was originally encountered using the boost shared memory allocator. </p> <p> The following patch appears to correct the behavior: </p> <pre class="wiki">128,129c128,129 &lt; void copy_n_and_update(Allocator &amp;, Iterator, size_type) const &lt; { BOOST_ASSERT(false); } --- &gt; void copy_n_and_update(Allocator &amp;a, Iterator p, size_type n) const &gt; { boost::container::uninitialized_value_init_alloc_n(a, n, p); } 142,143c142,143 &lt; void copy_n_and_update(Allocator &amp;, Iterator, size_type) const &lt; { BOOST_ASSERT(false); } --- &gt; void copy_n_and_update(Allocator &amp; a, Iterator n, size_type p) const &gt; { boost::container::uninitialized_default_init_alloc_n(a, n, p); } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13533 Trac 1.4.3 Paul Calabrese <calabrese_p@…> Fri, 20 Apr 2018 20:12:06 GMT attachment set https://svn.boost.org/trac10/ticket/13533 https://svn.boost.org/trac10/ticket/13533 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">alloc_test.cpp</span> </li> </ul> Ticket Ion Gaztañaga Mon, 23 Apr 2018 14:42:24 GMT <link>https://svn.boost.org/trac10/ticket/13533#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13533#comment:1</guid> <description> <p> Many thanks for the report and the test case. I'm afraied the patch is not correct as it constructs objects over already constructed ones (copy_n_and_update means that there are n objects already constructed in the range starting at the Iterator). </p> <p> I need to think about what is the expected output by the user in this case and implement a solution based on a copy, instead of a "uninitialized" copy. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Sun, 29 Apr 2018 10:39:50 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13533#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13533#comment:2</guid> <description> <p> The solution is to value-initialize an object and move it to the target. For default-initialization, this can be elided for POD-like types. Fixed in: </p> <p> <a class="ext-link" href="https://github.com/boostorg/container/commit/42c6be5887b34b67be4d54041acab12157d080f9"><span class="icon">​</span>https://github.com/boostorg/container/commit/42c6be5887b34b67be4d54041acab12157d080f9</a> </p> <p> Thanks for the report. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Sun, 29 Apr 2018 10:39:58 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/13533#comment:3 https://svn.boost.org/trac10/ticket/13533#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket