[Lemon-user] Issues using ReverseGraph adaptor - bug?
Alpar Juttner
alpar at cs.elte.hu
Wed Jun 7 10:01:19 CEST 2017
> When compiling on Linux (using gcc 7.1.0) it works well if I compile
> without any optimization flag. If I compile the same code using any
> optimization flag (e.g. –O1) I get a segmentation fault.
I know how you feel these types of bugs are very annoying.
The problem is with your code, not with LEMON.
This is the buggy line:
>
> lemon::> Dijkstra> <lemon::> ReverseDigraph> <> const>
> Digraph> >,
>
> Digraph> ::> ArcMap> <> int> >
> > dijkstra(lemon::reverseDigraph(dg), am_distance);
Here you create a temporary ReverseDigraph, pass its reference to
Dijkstra. But it is destructed and deallocated immediately after this
expresson. So when you actually run Dijkstra, it refers to an
unexisting object.
Without optimization, the bytes may still be there, that's why it works
by accident. But when optimization is switched on, this memory segment
is already reused, or probably even its constructor is optimized from
the code as apparently it is never used.
The correct way is either to allocate the adaptor permanently:
lemon::ReverseDigraph<const Digraph> rg(dg);
lemon::Dijkstra<lemon::ReverseDigraph<const Digraph>, Digraph::ArcMap<i
nt> > dijk(rg, am_distance);
dijk.run(u);
Or to use the function type interface:
lemon::dijkstra(lemon::reverseDigraph(dg), am_distance).predMap(preds).
distMap(dists).run(u);
or
lemon::dijkstra(lemon::reverseDigraph(dg), am_distance).path(p).run(u);
etc.
Best regards,
Alpár
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lemon.cs.elte.hu/pipermail/lemon-user/attachments/20170607/365ac1e3/attachment.html>
More information about the Lemon-user
mailing list