diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-06-19 18:43:10 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-06-19 18:43:10 +0100 |
commit | 89396a3d3babadc393d3d1db7c16c60ceac90e67 (patch) | |
tree | f927852426dc5cd714d71de0fdd841ee67156ca2 | |
parent | Clang-format (diff) | |
download | libadhocutil-0.8.1.tar.bz2 libadhocutil-0.8.1.tar.xz libadhocutil-0.8.1.zip |
Pass a cppchecklibadhocutil-0.8.1
-rw-r--r-- | Jamroot.jam | 1 | ||||
-rw-r--r-- | libadhocutil/buffer.cpp | 9 | ||||
-rw-r--r-- | libadhocutil/fileUtils.cpp | 2 | ||||
-rw-r--r-- | libadhocutil/globalStatic.h | 2 | ||||
-rw-r--r-- | libadhocutil/handle.h | 1 | ||||
-rw-r--r-- | libadhocutil/lazyPointer.h | 4 | ||||
-rw-r--r-- | libadhocutil/unittests/Jamfile.jam | 1 | ||||
-rw-r--r-- | libadhocutil/unittests/testCache.cpp | 2 | ||||
-rw-r--r-- | libadhocutil/unittests/testCompileTimeFormatter.cpp | 2 | ||||
-rw-r--r-- | libadhocutil/unittests/testFactory.cpp | 1 | ||||
-rw-r--r-- | libadhocutil/unittests/testMemStream.cpp | 1 | ||||
-rw-r--r-- | libadhocutil/unittests/testResourcePool.cpp | 12 |
12 files changed, 28 insertions, 10 deletions
diff --git a/Jamroot.jam b/Jamroot.jam index b4473a3..dfe522d 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -34,6 +34,7 @@ project <toolset>tidy:<xcheckxx>hicpp-signed-bitwise <toolset>tidy:<xcheckxx>hicpp-no-array-decay <toolset>tidy:<checkxx>performance-* + <toolset>tidy:<define>ICE_IGNORE_VERSION ; build-project libadhocutil ; diff --git a/libadhocutil/buffer.cpp b/libadhocutil/buffer.cpp index 07a57ea..e089c35 100644 --- a/libadhocutil/buffer.cpp +++ b/libadhocutil/buffer.cpp @@ -1,6 +1,7 @@ #include "buffer.h" #include <cstdio> #include <cstring> +#include <numeric> namespace AdHoc { @@ -241,11 +242,9 @@ namespace AdHoc { size_t Buffer::length() const { - size_t len = 0; - for (const Content::value_type & c : content) { - len += c->length(); - } - return len; + return std::accumulate(content.begin(), content.end(), 0U, [](auto && len, auto && c) { + return len + c->length(); + }); } Buffer & diff --git a/libadhocutil/fileUtils.cpp b/libadhocutil/fileUtils.cpp index 2d815a5..b648996 100644 --- a/libadhocutil/fileUtils.cpp +++ b/libadhocutil/fileUtils.cpp @@ -123,7 +123,7 @@ namespace AdHoc::FileUtils { void * MemMap::setupMapInt(int flags) const { - return mmap(nullptr, st.st_size, flags & (O_WRONLY | O_RDWR) ? PROT_WRITE : PROT_READ, MAP_SHARED, fh, 0); + return mmap(nullptr, st.st_size, (flags & (O_WRONLY | O_RDWR)) ? PROT_WRITE : PROT_READ, MAP_SHARED, fh, 0); } void * diff --git a/libadhocutil/globalStatic.h b/libadhocutil/globalStatic.h index f2443cb..a3847eb 100644 --- a/libadhocutil/globalStatic.h +++ b/libadhocutil/globalStatic.h @@ -18,7 +18,9 @@ namespace AdHoc { private: using Ptr = Object *; + // cppcheck-suppress unusedPrivateFunction static void createObject() __attribute__((constructor(101))); + // cppcheck-suppress unusedPrivateFunction static void deleteObject() __attribute__((destructor(101))); inline static Ptr & instance(); diff --git a/libadhocutil/handle.h b/libadhocutil/handle.h index a71859d..7547b99 100644 --- a/libadhocutil/handle.h +++ b/libadhocutil/handle.h @@ -39,6 +39,7 @@ namespace AdHoc { deleter = std::move(h.deleter); owning = h.owning; h.owning = false; + return *this; } /// Returns a reference to the managed object. diff --git a/libadhocutil/lazyPointer.h b/libadhocutil/lazyPointer.h index 667d321..baf5010 100644 --- a/libadhocutil/lazyPointer.h +++ b/libadhocutil/lazyPointer.h @@ -25,11 +25,11 @@ namespace AdHoc { /// @endcond /** Construct pointer with a factory function. */ - // NOLINTNEXTLINE(hicpp-explicit-conversions) + // cppcheck-suppress noExplicitConstructor; NOLINTNEXTLINE(hicpp-explicit-conversions) LazyPointer(Factory f) : source(f) { } /** Construct pointer with an instance value. */ - // NOLINTNEXTLINE(hicpp-explicit-conversions) + // cppcheck-suppress noExplicitConstructor; NOLINTNEXTLINE(hicpp-explicit-conversions) LazyPointer(P p) : source(p) { } /** Construct pointer with no factory or value. */ diff --git a/libadhocutil/unittests/Jamfile.jam b/libadhocutil/unittests/Jamfile.jam index aad8e24..9d1f304 100644 --- a/libadhocutil/unittests/Jamfile.jam +++ b/libadhocutil/unittests/Jamfile.jam @@ -22,6 +22,7 @@ project : requirements <toolset>tidy:<xcheckxx>bugprone-use-after-move <toolset>tidy:<xcheckxx>hicpp-invalid-access-moved + <toolset>tidy:<suppress>accessMoved ; h lorem-ipsum : lorem-ipsum.txt ; diff --git a/libadhocutil/unittests/testCache.cpp b/libadhocutil/unittests/testCache.cpp index 373d8d8..fe21868 100644 --- a/libadhocutil/unittests/testCache.cpp +++ b/libadhocutil/unittests/testCache.cpp @@ -8,7 +8,7 @@ // NOLINTNEXTLINE(hicpp-special-member-functions) class Obj { public: - // NOLINTNEXTLINE(hicpp-explicit-conversions) + // cppcheck-suppress noExplicitConstructor; NOLINTNEXTLINE(hicpp-explicit-conversions) Obj(int i) : v(i) { } void operator=(const Obj &) = delete; bool diff --git a/libadhocutil/unittests/testCompileTimeFormatter.cpp b/libadhocutil/unittests/testCompileTimeFormatter.cpp index ad5adbf..8dac170 100644 --- a/libadhocutil/unittests/testCompileTimeFormatter.cpp +++ b/libadhocutil/unittests/testCompileTimeFormatter.cpp @@ -123,7 +123,7 @@ static_assert(strchrnul<formatStringLiteral, 'e'>() == 3); static_assert(strchrnul<formatStringLiteral, 'f'>() == 7); #endif -BOOST_FIXTURE_TEST_SUITE(TestStreamWrite, std::stringstream) +BOOST_FIXTURE_TEST_SUITE(TestStreamWrite, std::stringstream); BOOST_AUTO_TEST_CASE(empty) { diff --git a/libadhocutil/unittests/testFactory.cpp b/libadhocutil/unittests/testFactory.cpp index 58ed9f7..d8bcb51 100644 --- a/libadhocutil/unittests/testFactory.cpp +++ b/libadhocutil/unittests/testFactory.cpp @@ -59,6 +59,7 @@ BOOST_AUTO_TEST_CASE(ready) BOOST_AUTO_TEST_CASE(get) { auto all = PluginManager::getDefault()->getAll(); + BOOST_CHECK_EQUAL(all.size(), 2); auto factory1 = PluginManager::getDefault()->get<BaseThingFactory>("a")->implementation(); auto factory2 = BaseThingFactory::get("a"); auto factory3 = BaseThingFactory::get("OtherImplOfThing"); diff --git a/libadhocutil/unittests/testMemStream.cpp b/libadhocutil/unittests/testMemStream.cpp index 5d26c42..89e0bf8 100644 --- a/libadhocutil/unittests/testMemStream.cpp +++ b/libadhocutil/unittests/testMemStream.cpp @@ -43,4 +43,5 @@ BOOST_AUTO_TEST_CASE(move_assign) MemStream ms1; MemStream ms2; ms2 = std::move(ms1); + BOOST_CHECK_EQUAL(ms2.length(), 0); } diff --git a/libadhocutil/unittests/testResourcePool.cpp b/libadhocutil/unittests/testResourcePool.cpp index 5f67424..a6db002 100644 --- a/libadhocutil/unittests/testResourcePool.cpp +++ b/libadhocutil/unittests/testResourcePool.cpp @@ -214,10 +214,13 @@ BOOST_AUTO_TEST_CASE(keepSome1) TRPSmall pool; { auto r1 = pool.get(); + BOOST_CHECK(r1); { auto r2 = pool.get(); + BOOST_CHECK(r2); { auto r3 = pool.get(); + BOOST_CHECK(r3); BOOST_REQUIRE_EQUAL(3, pool.inUseCount()); BOOST_REQUIRE_EQUAL(0, pool.availableCount()); BOOST_REQUIRE_EQUAL(3, MockResource::count); @@ -231,6 +234,7 @@ BOOST_AUTO_TEST_CASE(keepSome1) BOOST_REQUIRE_EQUAL(2, MockResource::count); { auto r2 = pool.get(); + BOOST_CHECK(r2); BOOST_REQUIRE_EQUAL(2, pool.inUseCount()); BOOST_REQUIRE_EQUAL(0, pool.availableCount()); BOOST_REQUIRE_EQUAL(2, MockResource::count); @@ -249,8 +253,11 @@ BOOST_AUTO_TEST_CASE(keepSome2) TRPSmall pool; { auto r1 = pool.get(); + BOOST_CHECK(r1); auto r2 = pool.get(); + BOOST_CHECK(r2); auto r3 = pool.get(); + BOOST_CHECK(r3); BOOST_REQUIRE_EQUAL(3, pool.inUseCount()); BOOST_REQUIRE_EQUAL(0, pool.availableCount()); BOOST_REQUIRE_EQUAL(3, MockResource::count); @@ -266,9 +273,12 @@ BOOST_AUTO_TEST_CASE(idle) { { auto r1 = pool.get(); + BOOST_CHECK(r1); auto r2 = pool.get(); + BOOST_CHECK(r2); } auto r3 = pool.get(); + BOOST_CHECK(r3); BOOST_REQUIRE_EQUAL(1, pool.inUseCount()); BOOST_REQUIRE_EQUAL(1, pool.availableCount()); BOOST_REQUIRE_EQUAL(2, MockResource::count); @@ -310,6 +320,7 @@ static void acquireAndKeepFor1Second(TRPSmall * pool, AdHoc::Semaphore & s) { auto r = pool->get(); + BOOST_CHECK(r); s.notify(); sleep(1); } @@ -410,6 +421,7 @@ BOOST_AUTO_TEST_CASE(returnFail) TRPReturnFail pool; { auto rh = pool.get(); + BOOST_CHECK(rh); BOOST_REQUIRE_EQUAL(0, pool.availableCount()); BOOST_REQUIRE_EQUAL(1, pool.inUseCount()); BOOST_REQUIRE_EQUAL(2, pool.freeCount()); |