From f00a8e98a2bff38afa3a1829d1f2a82b6637d534 Mon Sep 17 00:00:00 2001 From: Markus Pfeiffer Date: Mon, 13 May 2019 11:56:19 +0000 Subject: [PATCH] Fix ASAN failure (#8974) --- arangod/Graph/KShortestPathsFinder.cpp | 51 ++++++++++++++------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/arangod/Graph/KShortestPathsFinder.cpp b/arangod/Graph/KShortestPathsFinder.cpp index 6518bf51aa..a10643d166 100644 --- a/arangod/Graph/KShortestPathsFinder.cpp +++ b/arangod/Graph/KShortestPathsFinder.cpp @@ -39,7 +39,6 @@ #include #include - using namespace arangodb; using namespace arangodb::graph; @@ -58,7 +57,6 @@ bool KShortestPathsFinder::startKShortestPathsTraversal( _shortestPaths.clear(); _candidatePaths.clear(); - TRI_IF_FAILURE("TraversalOOMInitialize") { THROW_ARANGO_EXCEPTION(TRI_ERROR_DEBUG); } @@ -93,27 +91,29 @@ bool KShortestPathsFinder::computeShortestPath(VertexRef const& start, VertexRef return found; } -void KShortestPathsFinder::computeNeighbourhoodOfVertexCache(VertexRef vertex, Direction direction, std::vector*& res) { +void KShortestPathsFinder::computeNeighbourhoodOfVertexCache(VertexRef vertex, + Direction direction, + std::vector*& res) { auto lookup = _vertexCache.emplace(vertex, FoundVertex(vertex)).first; - auto& cache = lookup->second; // want to update the cached vertex in place + auto& cache = lookup->second; // want to update the cached vertex in place switch (direction) { - case BACKWARD: - if (!cache._hasCachedInNeighbours) { - computeNeighbourhoodOfVertex(vertex, direction, cache._inNeighbours); - cache._hasCachedInNeighbours = true; - } - res = &cache._inNeighbours; - break; - case FORWARD: - if (!cache._hasCachedOutNeighbours) { - computeNeighbourhoodOfVertex(vertex, direction, cache._outNeighbours); - cache._hasCachedOutNeighbours = true; - } - res = &cache._outNeighbours; - break; - default: - TRI_ASSERT(false); + case BACKWARD: + if (!cache._hasCachedInNeighbours) { + computeNeighbourhoodOfVertex(vertex, direction, cache._inNeighbours); + cache._hasCachedInNeighbours = true; + } + res = &cache._inNeighbours; + break; + case FORWARD: + if (!cache._hasCachedOutNeighbours) { + computeNeighbourhoodOfVertex(vertex, direction, cache._outNeighbours); + cache._hasCachedOutNeighbours = true; + } + res = &cache._outNeighbours; + break; + default: + TRI_ASSERT(false); } } @@ -209,8 +209,8 @@ bool KShortestPathsFinder::advanceFrontier(Ball& source, Ball const& target, } } else { source._frontier.insert(s._vertex, - std::make_unique(s._vertex, - std::move(s._edge), vr, weight)); + std::make_unique(s._vertex, std::move(s._edge), + vr, weight)); } } } @@ -303,8 +303,11 @@ bool KShortestPathsFinder::computeNextShortestPath(Path& result) { candidate.append(tmpPath, 0, tmpPath.length() - 1); candidate._branchpoint = i; - auto it = find_if(_candidatePaths.begin(), _candidatePaths.end(), [candidate](Path const& v) { return v._weight >= candidate._weight; } ); - if (!(*it == candidate)) { + auto it = find_if(_candidatePaths.begin(), _candidatePaths.end(), + [candidate](Path const& v) { + return v._weight >= candidate._weight; + }); + if (it == _candidatePaths.end() || !(*it == candidate)) { _candidatePaths.emplace(it, candidate); } }