From b385ffb12e34fe06eaa34904809bf9fdcf8a27bc Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sat, 1 Feb 2014 17:04:56 +0400 Subject: [PATCH] Running cppcheck with every build --- libuavcan/CMakeLists.txt | 11 +++++++++-- libuavcan/cppcheck.sh | 10 ++++++++++ libuavcan/include/uavcan/can_driver.hpp | 4 +++- libuavcan/test/can/io.cpp | 3 +++ 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100755 libuavcan/cppcheck.sh diff --git a/libuavcan/CMakeLists.txt b/libuavcan/CMakeLists.txt index d89126eef9..aa3d14e41d 100644 --- a/libuavcan/CMakeLists.txt +++ b/libuavcan/CMakeLists.txt @@ -26,7 +26,7 @@ add_library(uavcan SHARED ${LIBUAVCAN_CXX_FILES}) # TODO installation rules # -# Test +# Unit tests with gtest (optional) # find_package(GTest QUIET) if (GTEST_FOUND) @@ -47,8 +47,15 @@ if (GTEST_FOUND) # Tests run automatically upon successful build # If failing tests need to be investigated with debugger, use 'make --ignore-errors' add_custom_command(TARGET libuavcan_test POST_BUILD - COMMAND "./libuavcan_test" + COMMAND ./libuavcan_test WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) else (GTEST_FOUND) message(">> Google test library is not found, you will not be able to run tests") endif (GTEST_FOUND) + +# +# Static analysis with cppcheck (required), both library and unit test sources +# +add_custom_command(TARGET uavcan PRE_BUILD + COMMAND ./cppcheck.sh + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) diff --git a/libuavcan/cppcheck.sh b/libuavcan/cppcheck.sh new file mode 100755 index 0000000000..47ae39e8c2 --- /dev/null +++ b/libuavcan/cppcheck.sh @@ -0,0 +1,10 @@ +#!/bin/sh +# +# cppcheck static analysis +# For Debian based: apt-get install cppcheck +# + +# TODO: with future versions of cppcheck, add --library=glibc +cppcheck . --error-exitcode=1 --quiet --enable=all --platform=unix64 --std=c99 --std=c++11 \ + --inconclusive --inline-suppr --force --template=gcc \ + -Iinclude $@ diff --git a/libuavcan/include/uavcan/can_driver.hpp b/libuavcan/include/uavcan/can_driver.hpp index ccc47c91c7..22fb397a7c 100644 --- a/libuavcan/include/uavcan/can_driver.hpp +++ b/libuavcan/include/uavcan/can_driver.hpp @@ -30,7 +30,9 @@ struct CanFrame CanFrame() : id(0) , dlc(0) - { } + { + std::memset(data, 0, sizeof(data)); + } CanFrame(uint32_t id, const uint8_t* data, unsigned int dlc) : id(id) diff --git a/libuavcan/test/can/io.cpp b/libuavcan/test/can/io.cpp index ad36fe9d68..83d2868d0e 100644 --- a/libuavcan/test/can/io.cpp +++ b/libuavcan/test/can/io.cpp @@ -82,7 +82,10 @@ public: return 1; } + // cppcheck-suppress unusedFunction + // cppcheck-suppress functionConst int configureFilters(const uavcan::CanFilterConfig* filter_configs, int num_configs) { return -1; } + // cppcheck-suppress unusedFunction int getNumFilters() const { return 0; } uint64_t getNumErrors() const { return num_errors; } };