Skip to content

Commit

Permalink
Fix range check
Browse files Browse the repository at this point in the history
  • Loading branch information
pratzl committed Dec 21, 2023
1 parent c5780e5 commit 3f33630
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions include/graph/algorithm/shortest_paths.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <queue>
#include <vector>
#include <ranges>
#include <fmt/format.h>
#include "graph/graph.hpp"

#ifndef GRAPH_SHORTEST_PATHS_HPP
Expand Down Expand Up @@ -165,8 +166,9 @@ void dijkstra_shortest_paths(
using weight_type = invoke_result_t<WF, edge_reference_t<G>>;

size_t N(num_vertices(g));
if (source < N || source >= 0)
throw out_of_range("source is outside the vertices range");
if (source < 0 || source >= N) {
throw out_of_range(fmt::format("source {} is outside the vertices range [{},{})", source, 0, N));

Check warning on line 170 in include/graph/algorithm/shortest_paths.hpp

View check run for this annotation

Codecov / codecov/patch

include/graph/algorithm/shortest_paths.hpp#L170

Added line #L170 was not covered by tests
}

//std::ranges::fill(distances, numeric_limits<weight_type>::max());
distances[source] = 0;
Expand Down Expand Up @@ -275,9 +277,10 @@ void dijkstra_shortest_paths(
using id_type = vertex_id_t<G>;
using weight_type = invoke_result_t<WF, edge_reference_t<G>>;

size_t N(num_vertices(g));
if (source < N || source >= 0)
throw out_of_range("source is outside the vertices range");
const size_t N(num_vertices(g));
if (source < 0 || source >= N) {
throw out_of_range(fmt::format("source {} is outside the vertices range [{},{})", source, 0, N));

Check warning on line 282 in include/graph/algorithm/shortest_paths.hpp

View check run for this annotation

Codecov / codecov/patch

include/graph/algorithm/shortest_paths.hpp#L282

Added line #L282 was not covered by tests
}

//std::ranges::fill(distances, numeric_limits<weight_type>::max());
distances[source] = 0;
Expand Down

0 comments on commit 3f33630

Please sign in to comment.