Skip to content

Commit

Permalink
Merge pull request #1704 from ghutchis/fix-graph-crash
Browse files Browse the repository at this point in the history
Add double-check for addEdge to prevent potential crash
  • Loading branch information
ghutchis authored Sep 10, 2024
2 parents 96c13db + 97683c0 commit 434e588
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions avogadro/core/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ size_t Graph::addEdge(size_t a, size_t b)
m_subgraphDirty[subgraphA] || m_subgraphDirty[subgraphB];
for (size_t i : m_subgraphToVertices[subgraphB]) {
m_subgraphToVertices[subgraphA].insert(i);
m_vertexToSubgraph[i] = subgraphA;
if (i < m_vertexToSubgraph.size())
m_vertexToSubgraph[i] = subgraphA;
else
m_vertexToSubgraph.push_back(subgraphA);
}
// Just leave it empty, it could be reused
m_subgraphToVertices[subgraphB].clear();
Expand Down Expand Up @@ -433,8 +436,7 @@ size_t Graph::edgeCount() const

std::vector<size_t> Graph::neighbors(size_t index) const
{
if(index==size())
{
if (index == size()) {
std::vector<size_t> emptyVector;
return std::vector<size_t>(emptyVector);
}
Expand Down

0 comments on commit 434e588

Please sign in to comment.