Skip to content

Commit d7f9caf

Browse files
committed
add-Wnull-dereference and fix warnings
Signed-off-by: Ryan Friedman <[email protected]>
1 parent 67b3691 commit d7f9caf

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

nav2_common/cmake/nav2_package.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ macro(nav2_package)
3737
endif()
3838

3939
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
40-
add_compile_options(-Wall -Wextra -Wpedantic -Werror -Wdeprecated -fPIC -Wshadow)
40+
add_compile_options(-Wall -Wextra -Wpedantic -Werror -Wdeprecated -fPIC -Wshadow -Wnull-dereference)
4141
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wnon-virtual-dtor>")
4242
endif()
4343

nav2_costmap_2d/include/nav2_costmap_2d/denoise/image_processing.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,10 @@ class GroupsRemover
999999
// The group of pixels labeled 0 corresponds to empty map cells.
10001000
// Zero bin of the histogram is equal to the number of pixels in this group.
10011001
// Because the values of empty map cells should not be changed, we will reset this bin
1002-
groups_sizes.front() = 0; // don't change image background value
1002+
if (!groups_sizes.empty()) {
1003+
groups_sizes.front() = 0; // don't change image background value
1004+
}
1005+
10031006

10041007
// noise_labels_table[i] = true if group with label i is noise
10051008
std::vector<bool> noise_labels_table(groups_sizes.size());

nav2_mppi_controller/test/critic_manager_test.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,22 @@ class CriticManagerWrapper : public CriticManager
6565

6666
bool getDummyCriticInitialized()
6767
{
68-
return dynamic_cast<DummyCritic *>(critics_[0].get())->initialized_;
68+
const auto critic = critics_[0].get();
69+
if (critic == nullptr) {
70+
return false;
71+
}
72+
const auto dummy_critic = dynamic_cast<DummyCritic *>(critic);
73+
return dummy_critic == nullptr ? false : dummy_critic->initialized_;
6974
}
7075

7176
bool getDummyCriticScored()
7277
{
73-
return dynamic_cast<DummyCritic *>(critics_[0].get())->scored_;
78+
const auto critic = critics_[0].get();
79+
if (critic == nullptr) {
80+
return false;
81+
}
82+
const auto dummy_critic = dynamic_cast<DummyCritic *>(critic);
83+
return dummy_critic == nullptr ? false : dummy_critic->scored_;
7484
}
7585
};
7686

0 commit comments

Comments
 (0)