Skip to content

Commit

Permalink
Resolve "uninitialized" warning in optimize.cc
Browse files Browse the repository at this point in the history
tree_node contains alignment padding, which was "used" uninitialized.

Add copy, move constructors and assignment ops which ignore the padding,
from @tueda.
  • Loading branch information
jodavies committed May 7, 2024
1 parent 0183d64 commit 12ce0a5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions sources/optimize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,42 @@ class tree_node {

tree_node (int _var=0):
sum_results(0), num_visits(0), var(_var), finished(false) {}

tree_node(const tree_node& other):
childs(other.childs),
sum_results(other.sum_results),
num_visits(other.num_visits),
var(other.var),
finished(other.finished) {}

tree_node(const tree_node&& other) noexcept :
childs(std::move(other.childs)),
sum_results(other.sum_results),
num_visits(other.num_visits),
var(other.var),
finished(other.finished) {}

tree_node& operator=(const tree_node& other) {
if (this != &other) {
childs = other.childs;
sum_results = other.sum_results;
num_visits = other.num_visits;
var = other.var;
finished = other.finished;
}
return *this;
}

tree_node& operator=(tree_node&& other) noexcept {
if (this != &other) {
childs = std::move(other.childs);
sum_results = other.sum_results;
num_visits = other.num_visits;
var = other.var;
finished = other.finished;
}
return *this;
}
};

// global variables for multithreading
Expand Down

0 comments on commit 12ce0a5

Please sign in to comment.