From 3774f2b60f33e62abe6525e2047cd950287dd7e2 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Tue, 7 Aug 2018 14:41:05 +0200 Subject: [PATCH] Fix cppcheck warnings and cleanup suppression config - redundantAssignment - knownConditionTrueFalse --- cppcheck.supp | 23 +++++++------------ .../components/dbautostashingcomponent.cpp | 3 ++- src/blackgui/components/settingscomponent.cpp | 3 +-- src/blackgui/windowfinder.cpp | 5 ++-- .../simulation/remoteaircraftprovider.cpp | 1 + src/xswiftbus/dbusmessage.cpp | 3 +-- src/xswiftbus/libxplanemp | 2 +- 7 files changed, 17 insertions(+), 23 deletions(-) diff --git a/cppcheck.supp b/cppcheck.supp index 7dd94cd60..3f36cad5a 100644 --- a/cppcheck.supp +++ b/cppcheck.supp @@ -14,31 +14,24 @@ noExplicitConstructor // Ignore style issues in g2clib variableScope:src/plugins/weatherdata/gfs/g2clib/*.c -// std::initializer_list should always be passed by value -passedByValue:src/blackmisc/input/actionhotkeylist.h -passedByValue:src/blackmisc/network/rawfsdmessagelist.cpp -passedByValue:src/blackmisc/logcategorylist.h -passedByValue:src/blackmisc/platformset.cpp -passedByValue:src/blackmisc/geo/coordinategeodeticlist.cpp - -// variableHidingEnum for status message -variableHidingEnum:src/blackmisc/statusmessage.h - // Shared pointers should be passed by value passedByValue:src/blackmisc/lockfree.h -// False positive caused by cppcheck getting confused with preprocessor defines -ConfigurationNotChecked:src/xswiftbus/libxplanemp/src/XObjReadWrite.cpp - // Passing std::function by value is acceptable passedByValue:src/xswiftbus/libxplanemp/src/ResourceManager.h +passedByValue:tests/blackcore/expect.h passedByValue:src/xswiftbus/command.h // Unique pointers should be passed by value passedByValue:src/xswiftbus/menus.h passedByValue:src/xswiftbus/menus.cpp -// Suddenly appearing (KB 2018-03) issue here -// src/blackmisc/iterator.h 53 -> 'operator=' should return reference to 'this' instance. +// cppcheck cannot handle the advanced workaround in use operatorEqRetRefThis:src/blackmisc/iterator.h +// Ignore unusedFunction as it has too many false positives (especially in tests) +unusedFunction + +// Return value of those functions is not required. +ignoredReturnValue:src/blackmisc/dbusserver.cpp +ignoredReturnValue:src/blackmisc/simplecommandparser.cpp \ No newline at end of file diff --git a/src/blackgui/components/dbautostashingcomponent.cpp b/src/blackgui/components/dbautostashingcomponent.cpp index a076f9f6e..6c84ffdb6 100644 --- a/src/blackgui/components/dbautostashingcomponent.cpp +++ b/src/blackgui/components/dbautostashingcomponent.cpp @@ -237,9 +237,10 @@ namespace BlackGui const int all = models.size(); // maximum + int max = CDbStashComponent::MaxModelPublished; const QString maxStr(ui->le_MaxModelsStashed->text()); bool okMaxStr = true; - int max = maxStr.isEmpty() ? CDbStashComponent::MaxModelPublished : maxStr.toInt(&okMaxStr); + if (!maxStr.isEmpty()) { max = maxStr.toInt(&okMaxStr); } if (!okMaxStr || max > all) { max = all; } // override description diff --git a/src/blackgui/components/settingscomponent.cpp b/src/blackgui/components/settingscomponent.cpp index 333a74f2c..395c87fba 100644 --- a/src/blackgui/components/settingscomponent.cpp +++ b/src/blackgui/components/settingscomponent.cpp @@ -74,8 +74,7 @@ namespace BlackGui void CSettingsComponent::initActions() { - QAction *a = nullptr; - a = new QAction(this); + QAction *a = new QAction(this); a->setObjectName("overview"); a->setShortcut(QKeySequence(Qt::ALT + Qt::Key_S, Qt::Key_O)); connect(a, &QAction::triggered, this, &CSettingsComponent::onActionTriggered); diff --git a/src/blackgui/windowfinder.cpp b/src/blackgui/windowfinder.cpp index 0c419d8c4..1daf69ef2 100644 --- a/src/blackgui/windowfinder.cpp +++ b/src/blackgui/windowfinder.cpp @@ -23,12 +23,13 @@ namespace BlackGui { IWindowFinder *IWindowFinder::create() { - IWindowFinder *finder = nullptr; #if defined(Q_OS_WIN) - finder = new CWindowFinderWindows(); + IWindowFinder *finder = new CWindowFinderWindows(); #elif defined(Q_OS_LINUX) + IWindowFinder *finder = nullptr; #elif defined(Q_OS_MACOS) + IWindowFinder *finder = nullptr; #endif return finder; diff --git a/src/blackmisc/simulation/remoteaircraftprovider.cpp b/src/blackmisc/simulation/remoteaircraftprovider.cpp index 0a9d5e6a6..dcfc276b4 100644 --- a/src/blackmisc/simulation/remoteaircraftprovider.cpp +++ b/src/blackmisc/simulation/remoteaircraftprovider.cpp @@ -614,6 +614,7 @@ namespace BlackMisc constexpr bool globalOffsetTest = false; const CCallsign cs(situation.getCallsign()); + // cppcheck-suppress knownConditionTrueFalse if (!globalOffsetTest && !this->hasTestAltitudeOffset(cs)) { return situation; } CLength os; if (globalOffsetTest) diff --git a/src/xswiftbus/dbusmessage.cpp b/src/xswiftbus/dbusmessage.cpp index 29371b4f0..07a76ce36 100644 --- a/src/xswiftbus/dbusmessage.cpp +++ b/src/xswiftbus/dbusmessage.cpp @@ -53,8 +53,7 @@ namespace XSwiftBus std::string CDBusMessage::getSender() const { - const char *sender = nullptr; - sender = dbus_message_get_sender(m_message); + const char *sender = dbus_message_get_sender(m_message); return sender ? std::string(sender) : std::string(); } diff --git a/src/xswiftbus/libxplanemp b/src/xswiftbus/libxplanemp index 860edd58f..ef11f55ad 160000 --- a/src/xswiftbus/libxplanemp +++ b/src/xswiftbus/libxplanemp @@ -1 +1 @@ -Subproject commit 860edd58f0a8f2ae51506be92321b7998ba272b3 +Subproject commit ef11f55adc4ad6e3888a9f56981172e73d2111db