-
Notifications
You must be signed in to change notification settings - Fork 34
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
Explicitly check lib pointer for null #95
Conversation
Signed-off-by: Stephen Brawner <brawner@gmail.com>
ab9f56c
to
f1dc219
Compare
Force pushed the same change to rosidl_typesupport_cpp |
|
||
ASSERT_NE(lib, nullptr); | ||
// c-style assert is used to avoid false positive of clang static analysis because it can't | ||
// follow gtest asserts | ||
assert(nullptr != lib); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe a somewhat simpler solution here is:
ASSERT_NE(lib, nullptr); | |
// c-style assert is used to avoid false positive of clang static analysis because it can't | |
// follow gtest asserts | |
assert(nullptr != lib); | |
ASSERT(nullptr != lib); |
(I'm not against what you are doing here on principal, but I think it would be a little simpler to just stick with the GTest macros if possible).
Same goes for the change below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that scan-build is not following gtest macros to know that it's impossible for lib to be null. I kept the ASSERT_NE
in line 120 you'll notice so the assert in 123 is actually impossible to fail and gtest will report the test failure in line 120. But scan-build does acknowledge c-style assert
macros, so it will correctly identify that lib can't be null in line 124.
As far as I can find, you can annotate that functions won't return, but I couldn't find the same for macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just out of curiosity, mind changing ASSERT_NE
to ASSERT_TRUE(nullptr != lib)
and seeing if the analyzer still complains? It seems like there might be some built in magic for it.
https://reviews.llvm.org/D27773
https://clang.llvm.org/doxygen/GTestChecker_8cpp_source.html
Also found:
google/googletest#734
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that was my suggestion as well :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that seems to work. Fixed
Signed-off-by: Stephen Brawner <brawner@gmail.com>
rosidl_typesupport_c/test/test_message_type_support_dispatch.cpp
Outdated
Show resolved
Hide resolved
rosidl_typesupport_c/test/test_service_type_support_dispatch.cpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Stephen Brawner <brawner@gmail.com>
cmake warning on windows is due to an older cmake version in fastcdr. Unrelated to this PR. |
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 foranalyzer_noreturn
annotations to help it understand, but I believe that's only on functions. Clang does recognize standardassert
statements though, so I thought that would be the simplest solution here.Example
Signed-off-by: Stephen Brawner brawner@gmail.com