diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index b6b6e4f2d0..6a310dbaaa 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -183,7 +183,7 @@ namespace BlackCore::Afv::Clients m_connection->connectTo(cid, password, callsign, client, { // this is the callback when the connection has been established this, [=](bool authenticated) { - if (!myself) { return; } + if (!myself) { return; } // cppcheck-suppress knownConditionTrueFalse // HF stations aliased const QVector aliasedStations = m_connection->getAllAliasedStations(); diff --git a/src/blackcore/afv/connection/apiserverconnection.cpp b/src/blackcore/afv/connection/apiserverconnection.cpp index 4d6b979df3..7506c702b3 100644 --- a/src/blackcore/afv/connection/apiserverconnection.cpp +++ b/src/blackcore/afv/connection/apiserverconnection.cpp @@ -69,7 +69,7 @@ namespace BlackCore::Afv::Connection { this, [=](QNetworkReply *nwReply) { // called in "this" thread const QScopedPointer reply(nwReply); - if (!myself || isShuttingDown()) { return; } + if (!myself || isShuttingDown()) { return; } // cppcheck-suppress knownConditionTrueFalse this->logRequestDuration(reply.data(), "authentication"); if (reply->error() != QNetworkReply::NoError) @@ -278,7 +278,7 @@ namespace BlackCore::Afv::Connection QPointer myself(this); this->connectTo(m_username, m_password, m_client, m_networkVersion, { this, [=](bool authenticated) { - if (!myself) { return; } + if (!myself) { return; } // cppcheck-suppress knownConditionTrueFalse CLogMessage(this).info(u"API server authenticated '%1': %2") << m_username << boolToYesNo(authenticated); } }); } diff --git a/src/blackcore/afv/connection/clientconnection.cpp b/src/blackcore/afv/connection/clientconnection.cpp index fe6fc4f102..6babce7ced 100644 --- a/src/blackcore/afv/connection/clientconnection.cpp +++ b/src/blackcore/afv/connection/clientconnection.cpp @@ -50,7 +50,7 @@ namespace BlackCore::Afv::Connection { // callback called when connected this, [=](bool authenticated) { // callback when connection has been established - if (!myself) { return; } + if (!myself) { return; } // cppcheck-suppress knownConditionTrueFalse if (authenticated) { diff --git a/src/blackcore/afv/model/afvmapreader.cpp b/src/blackcore/afv/model/afvmapreader.cpp index 99f14fd944..345d35878e 100644 --- a/src/blackcore/afv/model/afvmapreader.cpp +++ b/src/blackcore/afv/model/afvmapreader.cpp @@ -32,7 +32,7 @@ namespace BlackCore::Afv::Model { loop.exec(); } - const QByteArray jsonData = reply->readAll(); + const QByteArray jsonData = reply ? reply->readAll() : QByteArray {}; if (reply) { reply->deleteLater(); } if (jsonData.isEmpty()) { return; } diff --git a/src/blackcore/airspacemonitor.cpp b/src/blackcore/airspacemonitor.cpp index 3e6cad6052..7e6a9ce909 100644 --- a/src/blackcore/airspacemonitor.cpp +++ b/src/blackcore/airspacemonitor.cpp @@ -186,7 +186,7 @@ namespace BlackCore eventLoop.stopWhen(m_fsdClient, &CFSDClient::flightPlanReceived, [=](const auto &cs, const auto &) { return cs == callsign; }); if (eventLoop.exec(1500)) { - if (!myself || !sApp || sApp->isShuttingDown()) { return CFlightPlan(); } + if (!myself || !sApp || sApp->isShuttingDown()) { return CFlightPlan(); } // cppcheck-suppress knownConditionTrueFalse if (m_flightPlanCache.contains(callsign)) { plan = m_flightPlanCache[callsign]; diff --git a/src/blackcore/context/contextsimulatorimpl.cpp b/src/blackcore/context/contextsimulatorimpl.cpp index a5362496c4..06969aaa71 100644 --- a/src/blackcore/context/contextsimulatorimpl.cpp +++ b/src/blackcore/context/contextsimulatorimpl.cpp @@ -644,7 +644,7 @@ namespace BlackCore::Context if (!m_simulatorPlugin.first.isUnspecified()) { ISimulator *simulator = m_simulatorPlugin.second; - if (simulator->isConnected()) + if (simulator && simulator->isConnected()) { // we are about to unload an connected simulator this->updateMarkAllAsNotRendered(); // without plugin nothing can be rendered diff --git a/src/blackcore/setupreader.cpp b/src/blackcore/setupreader.cpp index b68db6254d..37d8303fa2 100644 --- a/src/blackcore/setupreader.cpp +++ b/src/blackcore/setupreader.cpp @@ -117,7 +117,7 @@ namespace BlackCore // "retry" possible in some cases do { - if (ignoreCmdBootstrapUrl || !checkCmdBootstrapUrl || CNetworkUtils::canConnect(url, CNetworkUtils::getLongTimeoutMs())) + if (ignoreCmdBootstrapUrl || !checkCmdBootstrapUrl || CNetworkUtils::canConnect(url, CNetworkUtils::getLongTimeoutMs())) // cppcheck-suppress knownConditionTrueFalse { ok = true; break; @@ -308,7 +308,6 @@ namespace BlackCore { Q_ASSERT_X(!(webRead && localRead), Q_FUNC_INFO, "Local and web read together seems to be wrong"); CStatusMessageList msgs; - QPointer myself(this); bool available = false; if (webRead || localRead) diff --git a/src/blackgui/components/settingsnetworkserverscomponent.cpp b/src/blackgui/components/settingsnetworkserverscomponent.cpp index a41c644f5e..b6addb327d 100644 --- a/src/blackgui/components/settingsnetworkserverscomponent.cpp +++ b/src/blackgui/components/settingsnetworkserverscomponent.cpp @@ -98,7 +98,6 @@ namespace BlackGui::Components else { qFatal("Wrong sender"); - // cppcheck-suppress duplicateBreak return; } diff --git a/src/blackgui/loadindicator.cpp b/src/blackgui/loadindicator.cpp index 32b8010989..41018e63b7 100644 --- a/src/blackgui/loadindicator.cpp +++ b/src/blackgui/loadindicator.cpp @@ -62,7 +62,7 @@ namespace BlackGui if (processEvents && sGui) { sGui->processEventsToRefreshGui(); - if (!myself) { return -1; } // deleted in meantime (process events) + if (!myself) { return -1; } // cppcheck-suppress knownConditionTrueFalse // deleted in meantime (process events) } const int stopId = m_currentId++; // copy diff --git a/src/blackgui/menus/menuaction.cpp b/src/blackgui/menus/menuaction.cpp index b5134212d1..3725d6367f 100644 --- a/src/blackgui/menus/menuaction.cpp +++ b/src/blackgui/menus/menuaction.cpp @@ -534,7 +534,11 @@ namespace BlackGui::Menus } Q_ASSERT_X(subMenu, Q_FUNC_INFO, "Could not create sub menu"); - subMenu->setParent(parentMenu); + if (subMenu) + { + subMenu->setParent(parentMenu); + } + if (pathDepth > 0 && subMenu) { subMenus.insert(key, subMenu); diff --git a/src/blackgui/views/viewbase.cpp b/src/blackgui/views/viewbase.cpp index 79a79f13c6..d26ea0ea21 100644 --- a/src/blackgui/views/viewbase.cpp +++ b/src/blackgui/views/viewbase.cpp @@ -75,7 +75,7 @@ namespace BlackGui::Views const int c = m_model->update(container, sort); // resize after real update according to mode - if (presizeThresholdReached) + if (presizeThresholdReached) // cppcheck-suppress knownConditionTrueFalse { // currently no furhter actions } @@ -83,7 +83,7 @@ namespace BlackGui::Views { this->resizeToContents(); // mode based resize } - else if (presize && !presizeThresholdReached) + else if (presize && !presizeThresholdReached) // cppcheck-suppress knownConditionTrueFalse { // small amount of data not covered before this->fullResizeToContents(); diff --git a/src/blackinput/win/keyboardwindows.cpp b/src/blackinput/win/keyboardwindows.cpp index d6c7645821..747be9f2e7 100644 --- a/src/blackinput/win/keyboardwindows.cpp +++ b/src/blackinput/win/keyboardwindows.cpp @@ -143,8 +143,7 @@ namespace BlackInput bool CKeyboardWindows::init() { - // cppcheck-suppress knownConditionTrueFalse - if (useWindowsHook) + if (useWindowsHook) // cppcheck-suppress knownConditionTrueFalse { Q_ASSERT_X(g_keyboardWindows == nullptr, "CKeyboardWindows::init", "Windows supports only one keyboard instance. Cannot initialize a second one!"); g_keyboardWindows = this; diff --git a/src/blackmisc/aviation/aircraftsituation.cpp b/src/blackmisc/aviation/aircraftsituation.cpp index 8601d180fe..0e8db5edac 100644 --- a/src/blackmisc/aviation/aircraftsituation.cpp +++ b/src/blackmisc/aviation/aircraftsituation.cpp @@ -52,18 +52,18 @@ namespace BlackMisc::Aviation lights.setBeaconOn(true); lights.setNavOn(true); - if (gsKts > 5) - { - // mode taxi - lights.setTaxiOn(true); - lights.setLandingOn(false); - } - else if (gsKts > 30) + if (gsKts > 30) { // mode accelaration for takeoff lights.setTaxiOn(false); lights.setLandingOn(true); } + else if (gsKts > 5) + { + // mode taxi + lights.setTaxiOn(true); + lights.setLandingOn(false); + } else { // slow movements or parking diff --git a/src/blackmisc/aviation/flightplan.cpp b/src/blackmisc/aviation/flightplan.cpp index a75e97fa70..a77f08fffa 100644 --- a/src/blackmisc/aviation/flightplan.cpp +++ b/src/blackmisc/aviation/flightplan.cpp @@ -748,7 +748,7 @@ namespace BlackMisc::Aviation if (firstSplit.size() >= 2) { // format like B789/H-SDE1E2E3FGHIJ2J3J4J5M1RWXY/LB1D1 - QString equipment = firstSplit.size() >= 2 ? firstSplit[1] : ""; + QString equipment = firstSplit[1]; QStringList split = firstSplit[0].split('/'); if (split.size() >= 3) { diff --git a/src/blackmisc/aviation/selcal.cpp b/src/blackmisc/aviation/selcal.cpp index 96f46cd91b..4b2addae3a 100644 --- a/src/blackmisc/aviation/selcal.cpp +++ b/src/blackmisc/aviation/selcal.cpp @@ -74,7 +74,7 @@ namespace BlackMisc::Aviation if ((p3 = CSelcal::validCharacters().indexOf(codeUpper.at(2))) < 0) return false; if ((p4 = CSelcal::validCharacters().indexOf(codeUpper.at(3))) < 0) return false; if (p1 >= p2 || p3 >= p4) return false; // pair in alphabetical order - if (p1 == p3 || p2 == p3 || p2 == p4 || p3 == p4) return false; // given letter can be used only once in a SELCAL code + if (p1 == p3 || p2 == p3 || p2 == p4 || p3 == p4) return false; // cppcheck-suppress knownConditionTrueFalse // given letter can be used only once in a SELCAL code return true; } diff --git a/src/blackmisc/datacache.cpp b/src/blackmisc/datacache.cpp index 60ecc6d229..e46d709ff8 100644 --- a/src/blackmisc/datacache.cpp +++ b/src/blackmisc/datacache.cpp @@ -352,7 +352,7 @@ namespace BlackMisc class BLACKMISC_EXPORT CDataCacheRevision::Session { public: - // cppcheck-suppress unusedFunction + // cppcheck-suppress missingReturn Session(const QString &filename) : m_filename(filename) {} void updateSession(); const QUuid &uuid() const { return m_uuid; } diff --git a/src/blackmisc/dbusserver.cpp b/src/blackmisc/dbusserver.cpp index 92056c6536..81726dc3b6 100644 --- a/src/blackmisc/dbusserver.cpp +++ b/src/blackmisc/dbusserver.cpp @@ -380,8 +380,7 @@ namespace BlackMisc QString p = port.toLower().trimmed(); if (!p.isEmpty()) { - // cppcheck-suppress ignoredReturnValue - p.toShort(&ok); + p.toShort(&ok); // cppcheck-suppress ignoredReturnValue if (!ok) { p = ""; // was not a number diff --git a/src/blackmisc/fileutils.cpp b/src/blackmisc/fileutils.cpp index 350a9ce0d7..14bd9a1340 100644 --- a/src/blackmisc/fileutils.cpp +++ b/src/blackmisc/fileutils.cpp @@ -64,7 +64,7 @@ namespace BlackMisc bool CFileUtils::writeStringToLockedFile(const QString &content, const QString &fileNameAndPath) { QLockFile lock(fileNameAndPath + ".lock"); - lock.lock(); + if (!lock.lock()) { return false; } return writeStringToFile(content, fileNameAndPath); } @@ -81,7 +81,7 @@ namespace BlackMisc QString CFileUtils::readLockedFileToString(const QString &fileNameAndPath) { QLockFile lock(fileNameAndPath + ".lock"); - lock.lock(); + if (!lock.lock()) { return {}; } return readFileToString(fileNameAndPath); } diff --git a/src/blackmisc/mixin/mixinjson.h b/src/blackmisc/mixin/mixinjson.h index c66174fe92..5bb7969d76 100644 --- a/src/blackmisc/mixin/mixinjson.h +++ b/src/blackmisc/mixin/mixinjson.h @@ -161,10 +161,9 @@ namespace BlackMisc if (value.isUndefined()) { constexpr bool required = false; //! \fixme add RequiredForJson flag in metaclass system - // cppcheck-suppress knownConditionTrueFalse // QLatin1String used instead of QStringLiteral below since the latter causes an internal compiler bug // in GCC 8 and higher - if (required) { throw CJsonException(QLatin1String("Missing required member '%1'").arg(member.latin1Name())); } + if (required) { throw CJsonException(QLatin1String("Missing required member '%1'").arg(member.latin1Name())); } // cppcheck-suppress knownConditionTrueFalse } else { diff --git a/src/blackmisc/simplecommandparser.cpp b/src/blackmisc/simplecommandparser.cpp index 0ea035b70b..fe06e419e2 100644 --- a/src/blackmisc/simplecommandparser.cpp +++ b/src/blackmisc/simplecommandparser.cpp @@ -86,8 +86,7 @@ namespace BlackMisc const QString p = this->part(index); if (p.isEmpty()) { return false; } bool ok = false; - // cppcheck-suppress ignoredReturnValue - p.toInt(&ok); + p.toInt(&ok); // cppcheck-suppress ignoredReturnValue return ok; } diff --git a/src/blackmisc/simulation/aircraftmodellist.cpp b/src/blackmisc/simulation/aircraftmodellist.cpp index 2f4a8ae235..be19152c24 100644 --- a/src/blackmisc/simulation/aircraftmodellist.cpp +++ b/src/blackmisc/simulation/aircraftmodellist.cpp @@ -1030,14 +1030,11 @@ namespace BlackMisc::Simulation } const QMultiMap cps(counts.countPerSimulator()); CSimulatorInfo maxSim = cps.last(); - if (simulatorsRepresented > 0) + const int count = cps.lastKey(); // how many elements + const QList infoWithMaxValues = cps.values(count); // all with the same counts + for (const CSimulatorInfo &info : infoWithMaxValues) { - const int count = cps.lastKey(); // how many elements - const QList infoWithMaxValues = cps.values(count); // all with the same counts - for (const CSimulatorInfo &info : infoWithMaxValues) - { - maxSim.addSimulator(info); - } + maxSim.addSimulator(info); } return maxSim; } diff --git a/src/blackmisc/simulation/fscommon/vpilotrulesreader.cpp b/src/blackmisc/simulation/fscommon/vpilotrulesreader.cpp index 45f6866fd5..4cbd2ccc5a 100644 --- a/src/blackmisc/simulation/fscommon/vpilotrulesreader.cpp +++ b/src/blackmisc/simulation/fscommon/vpilotrulesreader.cpp @@ -148,7 +148,7 @@ namespace BlackMisc::Simulation::FsCommon if (m_shutdown) { return false; } loadedFiles++; bool s = this->loadFile(fn, rules); - if (!s) { this->m_fileListWithProblems.append(fn); } + if (!s) { filesWithProblems.append(fn); } } { diff --git a/src/plugins/simulator/fscommon/fsuipcimpl.cpp b/src/plugins/simulator/fscommon/fsuipcimpl.cpp index 5f13a67284..4612c334d8 100644 --- a/src/plugins/simulator/fscommon/fsuipcimpl.cpp +++ b/src/plugins/simulator/fscommon/fsuipcimpl.cpp @@ -498,8 +498,7 @@ namespace BlackSimPlugin::FsCommon // position const double latCorrectionFactor = 90.0 / (10001750.0 * 65536.0 * 65536.0); const double lonCorrectionFactor = 360.0 / (65536.0 * 65536.0 * 65536.0 * 65536.0); - // cppcheck-suppress shadowArgument - CAircraftSituation situation = aircraft.getSituation(); + CAircraftSituation situation = aircraft.getSituation(); // cppcheck-suppress shadowArgument CCoordinateGeodetic position = situation.getPosition(); CLatitude lat(latitudeRaw * latCorrectionFactor, CAngleUnit::deg()); CLongitude lon(longitudeRaw * lonCorrectionFactor, CAngleUnit::deg()); diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index 1f18302000..b50a1a4d63 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -1214,7 +1214,7 @@ namespace BlackSimPlugin::FsxCommon verified = true; } - if (!verified) + if (!verified) // cppcheck-suppress knownConditionTrueFalse { CLogMessage(this).info(u"Disable probes: '%1' failed to relase control") << cs.asString(); m_useFsxTerrainProbe = false; @@ -2641,8 +2641,7 @@ namespace BlackSimPlugin::FsxCommon void CSimulatorFsxCommon::traceSendId(const CSimConnectObject &simObject, const QString &functionName, const QString &details, bool forceTrace) { if (!forceTrace && !this->isTracingSendId()) { return; } - // cppcheck-suppress knownConditionTrueFalse - if (MaxSendIdTraces < 1) { return; } + if (MaxSendIdTraces < 1) { return; } // cppcheck-suppress knownConditionTrueFalse DWORD dwLastId = 0; const HRESULT hr = SimConnect_GetLastSentPacketID(m_hSimConnect, &dwLastId); if (isFailure(hr)) { return; } diff --git a/src/xswiftbus/dbusdispatcher.cpp b/src/xswiftbus/dbusdispatcher.cpp index 035c7de08d..16db3ef29c 100644 --- a/src/xswiftbus/dbusdispatcher.cpp +++ b/src/xswiftbus/dbusdispatcher.cpp @@ -190,7 +190,7 @@ namespace XSwiftBus return true; } - void CDBusDispatcher::dbusRemoveWatch(DBusWatch *watch) + void CDBusDispatcher::dbusRemoveWatch(const DBusWatch *watch) { for (auto it = m_watchers.begin(); it != m_watchers.end();) { diff --git a/src/xswiftbus/dbusdispatcher.h b/src/xswiftbus/dbusdispatcher.h index 9115bae797..4336c6c8f3 100644 --- a/src/xswiftbus/dbusdispatcher.h +++ b/src/xswiftbus/dbusdispatcher.h @@ -83,7 +83,7 @@ namespace XSwiftBus void dispatch(); dbus_bool_t dbusAddWatch(DBusWatch *watch); - void dbusRemoveWatch(DBusWatch *watch); + void dbusRemoveWatch(const DBusWatch *watch); void dbusWatchToggled(DBusWatch *watch); dbus_bool_t dbusAddTimeout(DBusTimeout *timeout); diff --git a/src/xswiftbus/menus.cpp b/src/xswiftbus/menus.cpp index 5f99dd459f..e019e526c5 100644 --- a/src/xswiftbus/menus.cpp +++ b/src/xswiftbus/menus.cpp @@ -103,6 +103,7 @@ namespace XSwiftBus return { XPLMCreateMenu(name.c_str(), m_data->id, XPLMAppendMenuItem(m_data->id, name.c_str(), nullptr, false), handler, itemsVoidPtr), false, std::move(items) }; } + // cppcheck-suppress constParameter void CMenu::handler(void *menuRef, void *itemRef) { if (menuRef && itemRef) diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index fd3e858103..ddbbcfbf11 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -980,8 +980,7 @@ namespace XSwiftBus int h = top - bottom; x -= left; y -= bottom; - // cppcheck-suppress knownConditionTrueFalse - if (DEBUG) { DEBUG_LOG("Follow aircraft coordinates w,h,x,y: " + std::to_string(w) + " " + std::to_string(h) + " " + std::to_string(x) + " " + std::to_string(y)); } + if (DEBUG) { DEBUG_LOG("Follow aircraft coordinates w,h,x,y: " + std::to_string(w) + " " + std::to_string(h) + " " + std::to_string(x) + " " + std::to_string(y)); } // cppcheck-suppress knownConditionTrueFalse if (traffic->m_lastMouseX == x && traffic->m_lastMouseY == y && traffic->m_lastMouseX >= 0 && traffic->m_lastMouseY >= 0) { // mouse NOT moving, we lost focus or we do NOT move anymore @@ -1099,8 +1098,7 @@ namespace XSwiftBus return 0; } - // cppcheck-suppress knownConditionTrueFalse - if (DEBUG) + if (DEBUG) // cppcheck-suppress knownConditionTrueFalse { DEBUG_LOG("Camera: " + pos2String(cameraPosition)); DEBUG_LOG("Follow aircraft " + traffic->m_followPlaneViewCallsign + " " + modelName);