Boost C++ Libraries: Ticket #13544: remove_vertex broken for adjacency_list https://svn.boost.org/trac10/ticket/13544 <p> Create a graph with three nodes, with the third node having an edge to the first node. Calling remove_vertex on the second node will then corrupt the m_property attribute of the edge of the third node. </p> <p> The graph template parameters are as follows. I'm not including the property classes' content. </p> <div class="wiki-code"><div class="code"><pre> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">adjacency_list</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">setS</span><span class="p">,</span> <span class="c1">// Container type for edges</span> <span class="n">boost</span><span class="o">::</span><span class="n">vecS</span><span class="p">,</span> <span class="c1">// Container type for vertices</span> <span class="n">boost</span><span class="o">::</span><span class="n">directedS</span><span class="p">,</span> <span class="c1">// Param for</span> <span class="c1">// directed/undirected/bidirectional</span> <span class="c1">// graph</span> <span class="n">Vertex</span><span class="p">,</span> <span class="c1">// Type for the vertices</span> <span class="n">Edge</span> <span class="c1">// Type for the edges</span> <span class="o">&gt;</span> <span class="n">Graph_t</span><span class="p">;</span> </pre></div></div><p> The culprit is the following method, in your adjacency_list.hpp. </p> <div class="wiki-code"><div class="code"><pre> <span class="k">template</span> <span class="o">&lt;</span><span class="k">class</span> <span class="nc">EdgeList</span><span class="p">,</span> <span class="k">class</span> <span class="nc">vertex_descriptor</span><span class="o">&gt;</span> <span class="kr">inline</span> <span class="kt">void</span> <span class="n">reindex_edge_list</span><span class="p">(</span><span class="n">EdgeList</span><span class="o">&amp;</span> <span class="n">el</span><span class="p">,</span> <span class="n">vertex_descriptor</span> <span class="n">u</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">disallow_parallel_edge_tag</span><span class="p">)</span> <span class="p">{</span> <span class="k">typename</span> <span class="n">EdgeList</span><span class="o">::</span><span class="n">iterator</span> <span class="n">ei</span> <span class="o">=</span> <span class="n">el</span><span class="p">.</span><span class="n">begin</span><span class="p">(),</span> <span class="n">e_end</span> <span class="o">=</span> <span class="n">el</span><span class="p">.</span><span class="n">end</span><span class="p">();</span> <span class="k">while</span> <span class="p">(</span><span class="n">ei</span> <span class="o">!=</span> <span class="n">e_end</span><span class="p">)</span> <span class="p">{</span> <span class="k">typename</span> <span class="n">EdgeList</span><span class="o">::</span><span class="n">value_type</span> <span class="n">ce</span> <span class="o">=</span> <span class="o">*</span><span class="n">ei</span><span class="p">;</span> <span class="o">++</span><span class="n">ei</span><span class="p">;</span> <span class="k">if</span> <span class="p">(</span><span class="n">ce</span><span class="p">.</span><span class="n">get_target</span><span class="p">()</span> <span class="o">&gt;</span> <span class="n">u</span><span class="p">)</span> <span class="p">{</span> <span class="n">el</span><span class="p">.</span><span class="n">erase</span><span class="p">(</span><span class="n">ce</span><span class="p">);</span> <span class="o">--</span><span class="n">ce</span><span class="p">.</span><span class="n">get_target</span><span class="p">();</span> <span class="n">el</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">ce</span><span class="p">);</span> <span class="p">}</span> <span class="p">}</span> <span class="p">}</span> </pre></div></div><p> When initializing the variable ce, its m_property field, which is a unique_ptr, is stolen from *ei, setting ei's field to null. If get_target is not bigger than u, ce is not re-inserted in el, leaving the old copy with the null pointer. </p> <p> Below is a suggested and tested fix. </p> <div class="wiki-code"><div class="code"><pre> <span class="k">template</span> <span class="o">&lt;</span><span class="k">class</span> <span class="nc">EdgeList</span><span class="p">,</span> <span class="k">class</span> <span class="nc">vertex_descriptor</span><span class="o">&gt;</span> <span class="kr">inline</span> <span class="kt">void</span> <span class="n">reindex_edge_list</span><span class="p">(</span><span class="n">EdgeList</span><span class="o">&amp;</span> <span class="n">el</span><span class="p">,</span> <span class="n">vertex_descriptor</span> <span class="n">u</span><span class="p">,</span> <span class="n">boost</span><span class="o">::</span><span class="n">disallow_parallel_edge_tag</span><span class="p">)</span> <span class="p">{</span> <span class="k">typename</span> <span class="n">EdgeList</span><span class="o">::</span><span class="n">iterator</span> <span class="n">ei</span> <span class="o">=</span> <span class="n">el</span><span class="p">.</span><span class="n">begin</span><span class="p">(),</span> <span class="n">e_end</span> <span class="o">=</span> <span class="n">el</span><span class="p">.</span><span class="n">end</span><span class="p">();</span> <span class="k">while</span> <span class="p">(</span><span class="n">ei</span> <span class="o">!=</span> <span class="n">e_end</span><span class="p">)</span> <span class="p">{</span> <span class="k">if</span> <span class="p">(</span><span class="n">ei</span><span class="o">-&gt;</span><span class="n">get_target</span><span class="p">()</span> <span class="o">&gt;</span> <span class="n">u</span><span class="p">)</span> <span class="p">{</span> <span class="k">typename</span> <span class="n">EdgeList</span><span class="o">::</span><span class="n">value_type</span> <span class="n">ce</span> <span class="o">=</span> <span class="o">*</span><span class="n">ei</span><span class="p">;</span> <span class="o">++</span><span class="n">ei</span><span class="p">;</span> <span class="n">el</span><span class="p">.</span><span class="n">erase</span><span class="p">(</span><span class="n">ce</span><span class="p">);</span> <span class="o">--</span><span class="n">ce</span><span class="p">.</span><span class="n">get_target</span><span class="p">();</span> <span class="n">el</span><span class="p">.</span><span class="n">insert</span><span class="p">(</span><span class="n">ce</span><span class="p">);</span> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="o">++</span><span class="n">ei</span><span class="p">;</span> <span class="p">}</span> <span class="p">}</span> <span class="p">}</span> </pre></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13544 Trac 1.4.3