From c3bed4c825f348bd1710446aa5204f02551dafe9 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 3 Aug 2014 13:47:33 +0400 Subject: [PATCH 1/6] libuavcan DSDLC template: suffix ULL instead of UL for 64-bit unsigned integers --- .../libuavcan_dsdl_compiler/data_type_template.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl b/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl index 2d01c7788c..6539e215ae 100644 --- a/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl +++ b/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/data_type_template.tmpl @@ -232,7 +232,7 @@ template ::uavcan::DataTypeSignature ${t.cpp_type_name}<_tmpl>::getDataTypeSignature() % endif { - ::uavcan::DataTypeSignature signature(${'0x%08X' % t.get_dsdl_signature()}UL); + ::uavcan::DataTypeSignature signature(${'0x%08X' % t.get_dsdl_signature()}ULL); #! scope_prefix, fields % for a in fields: ${scope_prefix}FieldTypes::${a.name}::extendDataTypeSignature(signature); From f2e028715a22c5bb6e8f8f0e56c874c7e82e1781 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 3 Aug 2014 14:01:56 +0400 Subject: [PATCH 2/6] libuavcan test: removed unused local type declarations --- libuavcan/test/marshal/float_spec.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/libuavcan/test/marshal/float_spec.cpp b/libuavcan/test/marshal/float_spec.cpp index 37dcd74f6a..3fa9b47225 100644 --- a/libuavcan/test/marshal/float_spec.cpp +++ b/libuavcan/test/marshal/float_spec.cpp @@ -15,11 +15,8 @@ TEST(FloatSpec, Limits) using uavcan::CastModeTruncate; typedef FloatSpec<16, CastModeSaturate> F16S; - typedef FloatSpec<16, CastModeTruncate> F16T; - typedef FloatSpec<32, CastModeSaturate> F32S; typedef FloatSpec<32, CastModeTruncate> F32T; typedef FloatSpec<64, CastModeSaturate> F64S; - typedef FloatSpec<64, CastModeTruncate> F64T; ASSERT_FALSE(F16S::IsExactRepresentation); ASSERT_FLOAT_EQ(65504.0, F16S::max()); From f40f00c0c71511668d8497f45514884219530f14 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 3 Aug 2014 14:04:04 +0400 Subject: [PATCH 3/6] cppcheck false positive suppression --- libuavcan/test/node/service_server.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libuavcan/test/node/service_server.cpp b/libuavcan/test/node/service_server.cpp index 5875569643..fcf5e3a145 100644 --- a/libuavcan/test/node/service_server.cpp +++ b/libuavcan/test/node/service_server.cpp @@ -96,6 +96,7 @@ TEST(ServiceServer, Basic) // Second frame ASSERT_TRUE(fr.parse(can_driver.ifaces[0].popTxFrame())); std::cout << fr.toString() << std::endl; + // cppcheck-suppress arrayIndexOutOfBounds ASSERT_STREQ(payloads[1], reinterpret_cast(fr.getPayloadPtr())); ASSERT_EQ(i, fr.getTransferID().get()); From 63843285a0ff32c2d85d17a580de474e9a8f1341 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 3 Aug 2014 14:10:58 +0400 Subject: [PATCH 4/6] libuavcan cppcheck definitions --- libuavcan/cppcheck.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/libuavcan/cppcheck.sh b/libuavcan/cppcheck.sh index 1f7265ea21..416cc506c5 100755 --- a/libuavcan/cppcheck.sh +++ b/libuavcan/cppcheck.sh @@ -14,4 +14,5 @@ echo "Number of threads for cppcheck: $num_cores" # TODO: with future versions of cppcheck, add --library=glibc cppcheck . --error-exitcode=1 --quiet --enable=all --platform=unix64 --std=c99 --std=c++11 \ --inline-suppr --force --template=gcc -j$num_cores \ + -U__BIGGEST_ALIGNMENT__ -UUAVCAN_MEM_POOL_BLOCK_SIZE -UBIG_ENDIAN -UBYTE_ORDER \ -Iinclude $@ From 6c972e6ba5170d62ac2e1d2abbbdd623c1fc82a2 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 3 Aug 2014 14:27:33 +0400 Subject: [PATCH 5/6] cppcheck warning suppressions --- libuavcan/include/uavcan/build_config.hpp | 2 +- libuavcan/include/uavcan/marshal/float_spec.hpp | 2 +- libuavcan/include/uavcan/marshal/integer_spec.hpp | 2 +- libuavcan/include/uavcan/node/service_server.hpp | 2 +- libuavcan/include/uavcan/node/subscriber.hpp | 2 +- libuavcan/src/marshal/uc_float_spec.cpp | 1 + libuavcan/test/node/test_node.hpp | 5 ++--- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libuavcan/include/uavcan/build_config.hpp b/libuavcan/include/uavcan/build_config.hpp index 1c2ce9e91e..1a686df550 100644 --- a/libuavcan/include/uavcan/build_config.hpp +++ b/libuavcan/include/uavcan/build_config.hpp @@ -168,7 +168,7 @@ struct UAVCAN_EXPORT IsDynamicallyAllocatable { static void check() { - char dummy[(sizeof(T) <= MemPoolBlockSize) ? 1 : -1]; + char dummy[(sizeof(T) <= MemPoolBlockSize) ? 1 : -1] = { '0' }; (void)dummy; } }; diff --git a/libuavcan/include/uavcan/marshal/float_spec.hpp b/libuavcan/include/uavcan/marshal/float_spec.hpp index 5fb1c93e58..f43d5a39da 100644 --- a/libuavcan/include/uavcan/marshal/float_spec.hpp +++ b/libuavcan/include/uavcan/marshal/float_spec.hpp @@ -210,7 +210,7 @@ class UAVCAN_EXPORT YamlStreamer > typedef typename FloatSpec::StorageType StorageType; public: - template + template // cppcheck-suppress passedByValue static void stream(Stream& s, const StorageType value, int) { s << value; diff --git a/libuavcan/include/uavcan/marshal/integer_spec.hpp b/libuavcan/include/uavcan/marshal/integer_spec.hpp index 179aaee3b0..01327b9889 100644 --- a/libuavcan/include/uavcan/marshal/integer_spec.hpp +++ b/libuavcan/include/uavcan/marshal/integer_spec.hpp @@ -153,7 +153,7 @@ class UAVCAN_EXPORT YamlStreamer > typedef typename RawType::StorageType StorageType; public: - template + template // cppcheck-suppress passedByValue static void stream(Stream& s, const StorageType value, int) { // Get rid of character types - we want its integer representation, not ASCII code diff --git a/libuavcan/include/uavcan/node/service_server.hpp b/libuavcan/include/uavcan/node/service_server.hpp index 6130773202..5ca6f970b5 100644 --- a/libuavcan/include/uavcan/node/service_server.hpp +++ b/libuavcan/include/uavcan/node/service_server.hpp @@ -76,7 +76,7 @@ private: uint32_t response_failure_count_; ResponseType response_; - void handleReceivedDataStruct(ReceivedDataStructure& request) + virtual void handleReceivedDataStruct(ReceivedDataStructure& request) { UAVCAN_ASSERT(request.getTransferType() == TransferTypeServiceRequest); if (try_implicit_cast(callback_, true)) diff --git a/libuavcan/include/uavcan/node/subscriber.hpp b/libuavcan/include/uavcan/node/subscriber.hpp index 75ed388fbf..62b15e11b7 100644 --- a/libuavcan/include/uavcan/node/subscriber.hpp +++ b/libuavcan/include/uavcan/node/subscriber.hpp @@ -69,7 +69,7 @@ private: Callback callback_; - void handleReceivedDataStruct(ReceivedDataStructure& msg) + virtual void handleReceivedDataStruct(ReceivedDataStructure& msg) { if (try_implicit_cast(callback_, true)) { diff --git a/libuavcan/src/marshal/uc_float_spec.cpp b/libuavcan/src/marshal/uc_float_spec.cpp index 49bd7c5413..acfaaf65b2 100644 --- a/libuavcan/src/marshal/uc_float_spec.cpp +++ b/libuavcan/src/marshal/uc_float_spec.cpp @@ -41,6 +41,7 @@ static inline bool isnan(T arg) #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 return std::isnan(arg); #else + // cppcheck-suppress duplicateExpression return arg != arg; #endif } diff --git a/libuavcan/test/node/test_node.hpp b/libuavcan/test/node/test_node.hpp index e287b8e3d5..02edfc3576 100644 --- a/libuavcan/test/node/test_node.hpp +++ b/libuavcan/test/node/test_node.hpp @@ -73,7 +73,7 @@ struct PairableCanDriver : public uavcan::ICanDriver, public uavcan::ICanIface assert(other); if (inout_masks.read == 1) { - inout_masks.read = (read_queue.size() || loopback_queue.size()) ? 1 : 0; + inout_masks.read = (!read_queue.empty() || !loopback_queue.empty()) ? 1 : 0; } if (inout_masks.read || inout_masks.write) { @@ -160,8 +160,7 @@ struct InterlinkedTestNodes nspins2 = nspins2 ? nspins2 : 1; while (nspins2 --> 0) { - int ret = -1; - ret = a.spin(uavcan::MonotonicDuration::fromMSec(1)); + int ret = a.spin(uavcan::MonotonicDuration::fromMSec(1)); if (ret < 0) { return ret; From b90fdf9f7d7da394c42304f14639032de506365a Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 3 Aug 2014 15:28:09 +0400 Subject: [PATCH 6/6] libuavcan unit test fix --- libuavcan/test/node/service_server.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libuavcan/test/node/service_server.cpp b/libuavcan/test/node/service_server.cpp index fcf5e3a145..9388aecd01 100644 --- a/libuavcan/test/node/service_server.cpp +++ b/libuavcan/test/node/service_server.cpp @@ -87,7 +87,7 @@ TEST(ServiceServer, Basic) uavcan::Frame fr; ASSERT_TRUE(fr.parse(can_driver.ifaces[0].popTxFrame())); std::cout << fr.toString() << std::endl; - ASSERT_STREQ(payloads[0], reinterpret_cast(fr.getPayloadPtr() + 2)); // Skipping CRC + ASSERT_FALSE(std::strncmp(payloads[0], reinterpret_cast(fr.getPayloadPtr() + 2), 5)); // No CRC ASSERT_EQ(i, fr.getTransferID().get()); ASSERT_EQ(uavcan::TransferTypeServiceResponse, fr.getTransferType()); @@ -97,7 +97,7 @@ TEST(ServiceServer, Basic) ASSERT_TRUE(fr.parse(can_driver.ifaces[0].popTxFrame())); std::cout << fr.toString() << std::endl; // cppcheck-suppress arrayIndexOutOfBounds - ASSERT_STREQ(payloads[1], reinterpret_cast(fr.getPayloadPtr())); + ASSERT_FALSE(std::strncmp(payloads[1], reinterpret_cast(fr.getPayloadPtr()), 7)); ASSERT_EQ(i, fr.getTransferID().get()); ASSERT_EQ(uavcan::TransferTypeServiceResponse, fr.getTransferType());