Skip to content

Commit 200101d

Browse files
authored
Added cppcoreguidelines-init-variables check to .clang-tidy (#3009)
* clang-tidy: Added cppcoreguidelines-init-variables * Fix warnings from cppcoreguideline-init-variables
1 parent 5d76cc6 commit 200101d

21 files changed

+63
-66
lines changed

.clang-tidy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Checks: >
66
cppcoreguidelines-avoid-capturing-lambda-coroutines,
77
cppcoreguidelines-avoid-goto,
88
cppcoreguidelines-avoid-non-const-global-variables,
9-
cppcoreguidelines-avoid-reference-coroutine-parameters
9+
cppcoreguidelines-avoid-reference-coroutine-parameters,
10+
cppcoreguidelines-init-variables
1011
1112
WarningsAsErrors: ''
1213
HeaderFilterRegex: './include'

include/bdAstar/bdAstar.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class Pgr_bdAstar : public Pgr_bidirectional<G> {
156156

157157
double dx = graph[v].x() - graph[u].x();
158158
double dy = graph[v].y() - graph[u].y();
159-
double current;
159+
double current = 0;
160160

161161
switch (m_heuristic) {
162162
case 0:

include/contraction/contractionGraph.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class Pgr_contractionGraph : public Pgr_base_graph<G, CH_vertex, CH_edge, t_dire
182182
*/
183183

184184
bool add_shortcut(const CH_edge &edge, V u, V v) {
185-
bool inserted;
185+
bool inserted = false;
186186
E e;
187187
if (edge.cost < 0) return false;
188188

@@ -395,7 +395,7 @@ class Pgr_contractionGraph : public Pgr_base_graph<G, CH_vertex, CH_edge, t_dire
395395
V u, V v, V w,
396396
std::vector<E> &shortcuts,
397397
std::ostringstream &log) {
398-
bool found_e;
398+
bool found_e = false;
399399
E e;
400400

401401
boost::tie(e, found_e) = boost::edge(u, w, this->graph);
@@ -423,7 +423,7 @@ class Pgr_contractionGraph : public Pgr_base_graph<G, CH_vertex, CH_edge, t_dire
423423
shortcut.add_contracted_edge_vertices(std::get<0>(e2));
424424

425425
// Add shortcut in the current graph (to go on the process)
426-
bool inserted;
426+
bool inserted = false;
427427
E s;
428428
boost::tie(s, inserted) = boost::add_edge(u, w, this->graph);
429429
this->graph[s]= shortcut;
@@ -434,16 +434,15 @@ class Pgr_contractionGraph : public Pgr_base_graph<G, CH_vertex, CH_edge, t_dire
434434
/*! @brief computes p_max used in the contraction hierarchies method
435435
*/
436436
int64_t compute_pmax(V u, V v, Identifiers<V> out_vertices) {
437-
int64_t p_max;
437+
int64_t p_max = 0;
438438
E e, f;
439-
bool found_e;
440-
p_max = 0;
439+
bool found_e = false;
441440
boost::tie(e, found_e) = boost::edge(u, v, this->graph);
442441

443442
if (found_e) {
444443
p_max = this->graph[e].cost;
445444
for (V w : out_vertices) {
446-
bool found_f;
445+
bool found_f = false;
447446
boost::tie(f, found_f) = boost::edge(v, w, this->graph);
448447
if ((found_f) && (u != w)) {
449448
if ((this->graph[e].cost + this->graph[f].cost) > p_max) {

include/contraction/contractionHierarchies.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void compute_shortcuts(
129129
for (const auto &w : out_vertices) {
130130
if ( u != w ) {
131131
typename G::E e, f, g;
132-
bool found_e, found_f, found_g;
132+
bool found_e = false, found_f = false, found_g = false;
133133
boost::tie(e, found_e) = boost::edge(u, v, graph.graph);
134134
boost::tie(f, found_f) = boost::edge(v, w, graph.graph);
135135
boost::tie(g, found_g) = boost::edge(u, w, graph.graph);
@@ -170,7 +170,7 @@ int64_t vertex_contraction(
170170
) {
171171
Identifiers<typename G::V> adjacent_in_vertices;
172172
Identifiers<typename G::V> adjacent_out_vertices;
173-
int64_t n_old_edges;
173+
int64_t n_old_edges = 0;
174174
std::vector<typename G::E> shortcut_edges;
175175

176176
if (directed) {
@@ -225,7 +225,7 @@ int64_t vertex_contraction(
225225
<< " shortcuts created, " << n_old_edges
226226
<< " old edges" << std::endl;
227227

228-
int64_t m;
228+
int64_t m = 0;
229229
m = static_cast<int64_t>(shortcut_edges.size())
230230
- static_cast<int64_t>(n_old_edges);
231231
log << " Metric: edge difference = " << shortcut_edges.size()

include/contraction/linearContraction.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,9 @@ class Pgr_linear {
107107
pgassert(v != w);
108108
pgassert(u != w);
109109

110-
E e, f;
111-
bool found_e, found_f;
112-
113110
if (graph.is_directed()) {
111+
E e, f;
112+
bool found_e = false, found_f = false;
114113
/*
115114
* u --> v --> w
116115
*/

include/cpp_common/base_graph.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ class Pgr_base_graph {
709709
auto u = get_V(edge.source);
710710
auto v = get_V(edge.target);
711711
if (edge.cost >= 0) {
712-
bool inserted;
712+
bool inserted = false;
713713
boost::tie(e, inserted) = boost::add_edge(u, v, graph);
714714
graph[e].cp_members(edge);
715715
}
@@ -730,7 +730,7 @@ class Pgr_base_graph {
730730
/**@}*/
731731

732732
template <typename T> void graph_add_edge(const T &edge, bool normal) {
733-
bool inserted;
733+
bool inserted = false;
734734
E e;
735735
if ((edge.cost < 0) && (edge.reverse_cost < 0)) return;
736736

@@ -761,7 +761,7 @@ class Pgr_base_graph {
761761
}
762762

763763
template <typename T> void graph_add_min_edge_no_parallel(const T &edge) {
764-
bool inserted;
764+
bool inserted = false;
765765
E e;
766766
if ((edge.cost < 0) && (edge.reverse_cost < 0)) return;
767767

@@ -776,7 +776,7 @@ class Pgr_base_graph {
776776
pgassert(vertices_map.find(edge.target) != vertices_map.end());
777777
if (edge.cost >= 0) {
778778
E e1;
779-
bool found;
779+
bool found = false;
780780
boost::tie(e1, found) = boost::edge(vm_s, vm_t, graph);
781781
if (found) {
782782
if (edge.cost < graph[e1].cost) {
@@ -793,7 +793,7 @@ class Pgr_base_graph {
793793
if (edge.reverse_cost >= 0
794794
&& (m_is_directed || (!m_is_directed && edge.cost != edge.reverse_cost))) {
795795
E e1;
796-
bool found;
796+
bool found = false;
797797
boost::tie(e1, found) = boost::edge(vm_t, vm_s, graph);
798798
if (found) {
799799
if (edge.reverse_cost < graph[e1].cost) {
@@ -816,7 +816,7 @@ class Pgr_base_graph {
816816
To Do: Read and apply edges with negative cost in function as it is
817817
*/
818818
template <typename T> void graph_add_neg_edge(const T &edge, bool normal = true) {
819-
bool inserted;
819+
bool inserted = false;
820820
E e;
821821

822822
auto vm_s = get_V(T_V(edge, true));

include/cpp_common/get_data.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ void get_data(
6161
Func func) {
6262
const int tuple_limit = 1000000;
6363

64-
size_t total_tuples;
65-
size_t valid_pgtuples;
64+
size_t total_tuples = 0;
65+
size_t valid_pgtuples = 0;
6666

6767
auto SPIplan = pgr_SPI_prepare(sql);
6868
auto SPIportal = pgr_SPI_cursor_open(SPIplan);
@@ -120,8 +120,8 @@ std::vector<Data_type> get_data(
120120
Func func) {
121121
const int tuple_limit = 1000000;
122122

123-
size_t total_tuples;
124-
size_t valid_pgtuples;
123+
size_t total_tuples = 0;
124+
size_t valid_pgtuples = 0;
125125

126126
auto SPIplan = pgr_SPI_prepare(sql.c_str());
127127
auto SPIportal = pgr_SPI_cursor_open(SPIplan);

include/lineGraph/lineGraphFull.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class Pgr_lineGraphFull : public Pgr_base_graph<G, T_V, T_E, t_directed> {
194194
const T &target,
195195
int64_t source_in_edge,
196196
int64_t source_out_edge) {
197-
bool inserted;
197+
bool inserted = false;
198198
E e;
199199

200200
pgassert(m_vertex_map.find({source, source_in_edge}) !=

src/chinese/chinesePostman_driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pgr_do_directedChPP(
7979

8080
pgrouting::graph::PgrDirectedChPPGraph digraph(edges);
8181

82-
double minCost;
82+
double minCost = NAN;
8383
minCost = digraph.DirectedChPP();
8484

8585
std::vector<Path_rt> pathEdges;

src/coloring/edgeColoring.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Pgr_edgeColoring::Pgr_edgeColoring(const std::vector<Edge_t> &edges) {
8484
/*
8585
* Inserting edges
8686
*/
87-
bool added;
87+
bool added = false;
8888
for (const auto &edge : edges) {
8989
auto v1 = get_boost_vertex(edge.source);
9090
auto v2 = get_boost_vertex(edge.target);

0 commit comments

Comments
 (0)