Commit f8d0e225 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Improve detection of invalid edge descriptors

This fixes a crash when a "valid" copy of an invalid edge descriptor is
removed from the graph. Now the invalidity of the descriptor is detected
and exposed.
parent 3b375c78
......@@ -204,8 +204,13 @@ struct get_edge_descriptor
{
PythonEdge<Graph>& pe = python::extract<PythonEdge<Graph>&>(e);
pe.CheckValid();
edge = pe.GetDescriptor();
pe.SetValid(false);
typename graph_traits<Graph>::out_edge_iterator e_begin, e_end;
tie(e_begin, e_end) = out_edges(source(pe.GetDescriptor(),g),g);
e_begin = std::find(e_begin, e_end, pe.GetDescriptor());
if (e_begin == e_end)
return; // invalid edge descriptor
edge = pe.GetDescriptor();
found = true;
}
};
......
......@@ -249,11 +249,9 @@ public:
if (_g().ptr() == Py_None)
return false;
GraphInterface& gi = python::extract<GraphInterface&>(_g());
return _valid &&
(gi._vertex_index[target(_e, gi._mg)] < num_vertices(gi._mg)) &&
(gi._vertex_index[source(_e, gi._mg)] < num_vertices(gi._mg)) &&
(target(_e, gi._mg) != graph_traits<Graph>::null_vertex()) &&
(source(_e, gi._mg) != graph_traits<Graph>::null_vertex());
GraphInterface::edge_t e(_e);
return (_valid && PythonVertex(_g, source(e, gi._mg)).IsValid() &&
PythonVertex(_g, target(e, gi._mg)).IsValid());
}
void SetValid(bool valid)
......@@ -263,7 +261,7 @@ public:
void CheckValid() const
{
if (!_valid)
if (!IsValid())
throw ValueException("invalid edge descriptor");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment