ros2 / rosidl_typesupport

Packages which provide the typesupport for ROS messages and services
Apache License 2.0
13 stars 34 forks source link

Explicitly check lib pointer for null #95

Closed brawner closed 3 years ago

brawner commented 3 years ago

This showed up as a false positive from clang static analysis. It's because it doesn't realize that gtest ASSERT_* macros will return. Clang does allow for analyzer_noreturn annotations to help it understand, but I believe that's only on functions. Clang does recognize standard assert statements though, so I thought that would be the simplest solution here.

Example

/home/brawner/workspace/ros2_master/src/ros2/rosidl_typesupport/rosidl_typesupport_c/test/test_message_type_support_dispatch.cpp:117:15: warning: Called C++ object pointer is null
  EXPECT_TRUE(lib->has_symbol("test_message_type_support"));
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/brawner/workspace/ros2_master/install/gtest_vendor/src/gtest_vendor/include/gtest/gtest.h:1969:23: note: expanded from macro 'EXPECT_TRUE'
  GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
                      ^~~~~~~~~
/home/brawner/workspace/ros2_master/install/gtest_vendor/src/gtest_vendor/include/gtest/internal/gtest-internal.h:1325:34: note: expanded from macro 'GTEST_TEST_BOOLEAN_'
      ::testing::AssertionResult(expression)) \
                                 ^~~~~~~~~~

Signed-off-by: Stephen Brawner brawner@gmail.com

brawner commented 3 years ago

Force pushed the same change to rosidl_typesupport_cpp

brawner commented 3 years ago

Testing --packages-select rosidl_typesupport_c rosidl_typesupport_cpp

brawner commented 3 years ago
brawner commented 3 years ago
brawner commented 3 years ago

cmake warning on windows is due to an older cmake version in fastcdr. Unrelated to this PR.