Open llvmbot opened 8 years ago
I have a method that should not be passed a null pointer under normal operation, so I have declared it like so (in C):
uint16_t CRC_xmodem(const uint8_t* data, const uint16_t length) attribute((nonnull));
but in unit testing I want to pass it a null pointer to ensure it accepts it gracefully. To avoid a compiler warning, I do this like so (in C++, using catch.hpp if that's relevant):
TEST_CASE("CRC_xmodem null pointer produces zero, "[crc]") {
CHECK( 0 == CRC_xmodem(NULL, 0) );
}
This is sufficient to suppress the compile-time warnings, but scan-build still produces a warning:-
snip/crc/crc_unittest.cpp:34:21: warning: Null pointer passed as an argument to a 'nonnull' parameter CHECK( 0 == CRC_xmodem(NULL, 0) ); ^ ~~~~
Currently I'm suppressing the warning using #ifndef __clang_analyzer__ but it would be tidier if the clang analyser respected the GCC pragma.
assigned to @tkremenek
Extended Description
I have a method that should not be passed a null pointer under normal operation, so I have declared it like so (in C):
uint16_t CRC_xmodem(const uint8_t* data, const uint16_t length) attribute((nonnull));
but in unit testing I want to pass it a null pointer to ensure it accepts it gracefully. To avoid a compiler warning, I do this like so (in C++, using catch.hpp if that's relevant):
TEST_CASE("CRC_xmodem null pointer produces zero, "[crc]") {
pragma GCC diagnostic ignored "-Wnonnull"
pragma GCC diagnostic pop
}
This is sufficient to suppress the compile-time warnings, but scan-build still produces a warning:-
snip/crc/crc_unittest.cpp:34:21: warning: Null pointer passed as an argument to a 'nonnull' parameter CHECK( 0 == CRC_xmodem(NULL, 0) ); ^ ~~~~
Currently I'm suppressing the warning using #ifndef __clang_analyzer__ but it would be tidier if the clang analyser respected the GCC pragma.