Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue1112] Add flag -Wzero-as-null-pointer-constant and fix resulting warnings. #177

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cmake_modules/FastDownwardMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ macro(fast_downward_set_compiler_flags)
check_and_set_compiler_flag( "-std=c++20" )

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wnon-virtual-dtor -Wfloat-conversion -Wmissing-declarations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wnon-virtual-dtor -Wfloat-conversion -Wmissing-declarations -Wzero-as-null-pointer-constant")

if (CMAKE_COMPILER_IS_GNUCXX
AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12
Expand Down
8 changes: 4 additions & 4 deletions src/search/heuristics/cea_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct LocalProblemNode {
cost(-1),
expanded(false),
context(context_size, -1),
reached_by(0) {
reached_by(nullptr) {
}

~LocalProblemNode() {
Expand Down Expand Up @@ -222,7 +222,7 @@ void ContextEnhancedAdditiveHeuristic::set_up_local_problem(
to_node.expanded = false;
to_node.cost = numeric_limits<int>::max();
to_node.waiting_list.clear();
to_node.reached_by = 0;
to_node.reached_by = nullptr;
}

LocalProblemNode *start = &problem->nodes[start_value];
Expand Down Expand Up @@ -359,7 +359,7 @@ void ContextEnhancedAdditiveHeuristic::mark_helpful_transitions(
assert(node->cost >= 0 && node->cost < numeric_limits<int>::max());
LocalTransition *first_on_path = node->reached_by;
if (first_on_path) {
node->reached_by = 0; // Clear to avoid revisiting this node later.
node->reached_by = nullptr; // Clear to avoid revisiting this node later.
if (first_on_path->target_cost == first_on_path->action_cost) {
// Transition possibly applicable.
const ValueTransitionLabel &label = *first_on_path->label;
Expand Down Expand Up @@ -425,7 +425,7 @@ ContextEnhancedAdditiveHeuristic::ContextEnhancedAdditiveHeuristic(
VariablesProxy vars = task_proxy.get_variables();
local_problem_index.resize(vars.size());
for (VariableProxy var : vars)
local_problem_index[var.get_id()].resize(var.get_domain_size(), 0);
local_problem_index[var.get_id()].resize(var.get_domain_size(), nullptr);
}

ContextEnhancedAdditiveHeuristic::~ContextEnhancedAdditiveHeuristic() {
Expand Down
8 changes: 4 additions & 4 deletions src/search/heuristics/cg_heuristic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ int CGHeuristic::get_transition_cost(const State &state,
if (start->distances.empty()) {
// Initialize data of initial node.
start->distances.resize(dtg->nodes.size(), numeric_limits<int>::max());
start->helpful_transitions.resize(dtg->nodes.size(), 0);
start->helpful_transitions.resize(dtg->nodes.size(), nullptr);
start->distances[start_val] = 0;
start->reached_from = 0;
start->reached_by = 0;
start->reached_from = nullptr;
start->reached_by = nullptr;
start->children_state.resize(dtg->local_to_global_child.size());
for (size_t i = 0; i < dtg->local_to_global_child.size(); ++i) {
start->children_state[i] =
Expand Down Expand Up @@ -188,7 +188,7 @@ int CGHeuristic::get_transition_cost(const State &state,
target->reached_from = source;
target->reached_by = &label;

if (current_helpful_transition == 0) {
if (current_helpful_transition == nullptr) {
// This transition starts at the start node;
// no helpful transitions recorded yet.
start->helpful_transitions[target->value] = &label;
Expand Down
3 changes: 2 additions & 1 deletion src/search/heuristics/domain_transition_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ struct ValueNode {
ValueTransitionLabel *reached_by;

ValueNode(DomainTransitionGraph *parent, int val)
: parent_graph(parent), value(val), reached_from(0), reached_by(0) {}
: parent_graph(parent), value(val), reached_from(nullptr),
reached_by(nullptr) {}
};

class DomainTransitionGraph {
Expand Down
2 changes: 1 addition & 1 deletion src/search/heuristics/lm_cut_landmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void LandmarkCutLandmarks::setup_exploration_queue() {

for (RelaxedOperator &op : relaxed_operators) {
op.unsatisfied_preconditions = op.preconditions.size();
op.h_max_supporter = 0;
op.h_max_supporter = nullptr;
op.h_max_supporter_cost = numeric_limits<int>::max();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/search/landmarks/landmark_factory_merged.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ LandmarkNode *LandmarkFactoryMerged::get_matching_landmark(const Landmark &landm
if (lm_graph->contains_simple_landmark(lm_fact))
return &lm_graph->get_simple_landmark(lm_fact);
else
return 0;
return nullptr;
} else if (landmark.disjunctive) {
set<FactPair> lm_facts(landmark.facts.begin(), landmark.facts.end());
if (lm_graph->contains_identical_disjunctive_landmark(lm_facts))
return &lm_graph->get_disjunctive_landmark(landmark.facts[0]);
else
return 0;
return nullptr;
} else if (landmark.conjunctive) {
cerr << "Don't know how to handle conjunctive landmarks yet" << endl;
utils::exit_with(ExitCode::SEARCH_UNSUPPORTED);
}
return 0;
return nullptr;
}

void LandmarkFactoryMerged::generate_landmarks(
Expand Down
1 change: 1 addition & 0 deletions src/search/lp/soplex_solver_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifdef __GNUG__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#if (__GNUG__ >= 11) || (__clang_major__ >= 12)
#pragma GCC diagnostic ignored "-Wdeprecated-enum-enum-conversion"
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/search/pdbs/match_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ MatchTree::~MatchTree() {
void MatchTree::insert_recursive(
int op_id, const vector<FactPair> &regression_preconditions,
int pre_index, Node **edge_from_parent) {
if (*edge_from_parent == 0) {
if (*edge_from_parent == nullptr) {
// We don't exist yet: create a new node.
*edge_from_parent = new Node();
}
Expand Down Expand Up @@ -111,7 +111,7 @@ void MatchTree::insert_recursive(

/* Set up edge to the correct child (for which we want to call
this function recursively). */
Node **edge_to_child = 0;
Node **edge_to_child = nullptr;
if (node->var_id == fact.var) {
// Operator has a precondition on the variable tested by node.
edge_to_child = &node->successors[fact.value];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ PatternCollectionGeneratorHillclimbing::PatternCollectionGeneratorHillclimbing(c
max_time(opts.get<double>("max_time")),
rng(utils::parse_rng_from_options(opts)),
num_rejected(0),
hill_climbing_timer(0) {
hill_climbing_timer(nullptr) {
}

int PatternCollectionGeneratorHillclimbing::generate_candidate_pdbs(
Expand Down
12 changes: 6 additions & 6 deletions src/search/utils/system_unix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void register_event_handlers() {
// On exit or when receiving certain signals such as SIGINT (Ctrl-C),
// print the peak memory usage.
#if OPERATING_SYSTEM == LINUX
on_exit(exit_handler, 0);
on_exit(exit_handler, nullptr);
#elif OPERATING_SYSTEM == OSX
atexit(exit_handler);
#endif
Expand All @@ -243,11 +243,11 @@ void register_event_handlers() {
// Reset handler to default action after completion.
default_signal_action.sa_flags = SA_RESETHAND;

sigaction(SIGABRT, &default_signal_action, 0);
sigaction(SIGTERM, &default_signal_action, 0);
sigaction(SIGSEGV, &default_signal_action, 0);
sigaction(SIGINT, &default_signal_action, 0);
sigaction(SIGXCPU, &default_signal_action, 0);
sigaction(SIGABRT, &default_signal_action, nullptr);
sigaction(SIGTERM, &default_signal_action, nullptr);
sigaction(SIGSEGV, &default_signal_action, nullptr);
sigaction(SIGINT, &default_signal_action, nullptr);
sigaction(SIGXCPU, &default_signal_action, nullptr);
}

void report_exit_code_reentrant(ExitCode exitcode) {
Expand Down