Ensure named_graph base class is initialized before accessing it#415
Merged
jeremy-murphy merged 1 commit intoboostorg:developfrom Feb 4, 2025
Merged
Conversation
Collaborator
|
Thanks for making an incremental improvement to the quality of this library! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes the issue that a
boost::adjacency_listdoes not properly initialize it'sgraph::maybe_named_graphbase before calling functions on it.More specifically, the following crashes:
The reason this happens is because:
boost::adjacency_listinherits fromdetail::adj_list_gen<...>andgraph::maybe_named_graph<...>boost::adjacency_listtypedefsdetail::adj_list_gen<...>asBaseBase(x)as its very first "action", wherexisgraphAvec_adj_list_impl<...>(graphA), which callscopy_impl(graphA)boost::add_vertexonadjacency_list &(whichvec_adj_list_implcan cast itself to due to CRTP)vec_adj_list_impl::added_vertex()which is "injected" intoadjacency_listvia thegraph::maybe_named_graphinheritance.When this last call (
added_vertex()) happens on graphs that are not named graphs, nothing happens (i.e.added_vertex()is a no-op). However, it does do a bunch of stuff if the graph is a named graph (and thus inherits fromgraph::named_graph. In that case there's some uninitialized size member which hasn't been initialized yet, which gets used at some point and then the whole thing blows up.The fix is simple: just inherit from
graph::maybe_named_graphfirst, such that the call toBase(x)happens after thegraph::maybe_named_graphbase has already been default initialized.Note that there's no move constructor, i.e. the copy constructor will always get called even if an rvalue
graph_tis passed to the constructor. So the above also happens for e.g.graph_t graphB{getGraph()}.