Fix cppcheck warnings

This commit is contained in:
Lars Toenning
2023-04-16 21:02:55 +02:00
parent ac04aa3a63
commit 7ef0e6e1eb
28 changed files with 45 additions and 53 deletions

View File

@@ -183,7 +183,7 @@ namespace BlackCore::Afv::Clients
m_connection->connectTo(cid, password, callsign, client, m_connection->connectTo(cid, password, callsign, client,
{ // this is the callback when the connection has been established { // this is the callback when the connection has been established
this, [=](bool authenticated) { this, [=](bool authenticated) {
if (!myself) { return; } if (!myself) { return; } // cppcheck-suppress knownConditionTrueFalse
// HF stations aliased // HF stations aliased
const QVector<StationDto> aliasedStations = m_connection->getAllAliasedStations(); const QVector<StationDto> aliasedStations = m_connection->getAllAliasedStations();

View File

@@ -69,7 +69,7 @@ namespace BlackCore::Afv::Connection
{ this, [=](QNetworkReply *nwReply) { { this, [=](QNetworkReply *nwReply) {
// called in "this" thread // called in "this" thread
const QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nwReply); const QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nwReply);
if (!myself || isShuttingDown()) { return; } if (!myself || isShuttingDown()) { return; } // cppcheck-suppress knownConditionTrueFalse
this->logRequestDuration(reply.data(), "authentication"); this->logRequestDuration(reply.data(), "authentication");
if (reply->error() != QNetworkReply::NoError) if (reply->error() != QNetworkReply::NoError)
@@ -278,7 +278,7 @@ namespace BlackCore::Afv::Connection
QPointer<CApiServerConnection> myself(this); QPointer<CApiServerConnection> myself(this);
this->connectTo(m_username, m_password, m_client, m_networkVersion, this->connectTo(m_username, m_password, m_client, m_networkVersion,
{ this, [=](bool authenticated) { { 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); CLogMessage(this).info(u"API server authenticated '%1': %2") << m_username << boolToYesNo(authenticated);
} }); } });
} }

View File

@@ -50,7 +50,7 @@ namespace BlackCore::Afv::Connection
{ // callback called when connected { // callback called when connected
this, [=](bool authenticated) { this, [=](bool authenticated) {
// callback when connection has been established // callback when connection has been established
if (!myself) { return; } if (!myself) { return; } // cppcheck-suppress knownConditionTrueFalse
if (authenticated) if (authenticated)
{ {

View File

@@ -32,7 +32,7 @@ namespace BlackCore::Afv::Model
{ {
loop.exec(); loop.exec();
} }
const QByteArray jsonData = reply->readAll(); const QByteArray jsonData = reply ? reply->readAll() : QByteArray {};
if (reply) { reply->deleteLater(); } if (reply) { reply->deleteLater(); }
if (jsonData.isEmpty()) { return; } if (jsonData.isEmpty()) { return; }

View File

@@ -186,7 +186,7 @@ namespace BlackCore
eventLoop.stopWhen(m_fsdClient, &CFSDClient::flightPlanReceived, [=](const auto &cs, const auto &) { return cs == callsign; }); eventLoop.stopWhen(m_fsdClient, &CFSDClient::flightPlanReceived, [=](const auto &cs, const auto &) { return cs == callsign; });
if (eventLoop.exec(1500)) 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)) if (m_flightPlanCache.contains(callsign))
{ {
plan = m_flightPlanCache[callsign]; plan = m_flightPlanCache[callsign];

View File

@@ -644,7 +644,7 @@ namespace BlackCore::Context
if (!m_simulatorPlugin.first.isUnspecified()) if (!m_simulatorPlugin.first.isUnspecified())
{ {
ISimulator *simulator = m_simulatorPlugin.second; ISimulator *simulator = m_simulatorPlugin.second;
if (simulator->isConnected()) if (simulator && simulator->isConnected())
{ {
// we are about to unload an connected simulator // we are about to unload an connected simulator
this->updateMarkAllAsNotRendered(); // without plugin nothing can be rendered this->updateMarkAllAsNotRendered(); // without plugin nothing can be rendered

View File

@@ -117,7 +117,7 @@ namespace BlackCore
// "retry" possible in some cases // "retry" possible in some cases
do do
{ {
if (ignoreCmdBootstrapUrl || !checkCmdBootstrapUrl || CNetworkUtils::canConnect(url, CNetworkUtils::getLongTimeoutMs())) if (ignoreCmdBootstrapUrl || !checkCmdBootstrapUrl || CNetworkUtils::canConnect(url, CNetworkUtils::getLongTimeoutMs())) // cppcheck-suppress knownConditionTrueFalse
{ {
ok = true; ok = true;
break; break;
@@ -308,7 +308,6 @@ namespace BlackCore
{ {
Q_ASSERT_X(!(webRead && localRead), Q_FUNC_INFO, "Local and web read together seems to be wrong"); Q_ASSERT_X(!(webRead && localRead), Q_FUNC_INFO, "Local and web read together seems to be wrong");
CStatusMessageList msgs; CStatusMessageList msgs;
QPointer<CSetupReader> myself(this);
bool available = false; bool available = false;
if (webRead || localRead) if (webRead || localRead)

View File

@@ -98,7 +98,6 @@ namespace BlackGui::Components
else else
{ {
qFatal("Wrong sender"); qFatal("Wrong sender");
// cppcheck-suppress duplicateBreak
return; return;
} }

View File

@@ -62,7 +62,7 @@ namespace BlackGui
if (processEvents && sGui) if (processEvents && sGui)
{ {
sGui->processEventsToRefreshGui(); 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 const int stopId = m_currentId++; // copy

View File

@@ -534,7 +534,11 @@ namespace BlackGui::Menus
} }
Q_ASSERT_X(subMenu, Q_FUNC_INFO, "Could not create sub menu"); Q_ASSERT_X(subMenu, Q_FUNC_INFO, "Could not create sub menu");
subMenu->setParent(parentMenu); if (subMenu)
{
subMenu->setParent(parentMenu);
}
if (pathDepth > 0 && subMenu) if (pathDepth > 0 && subMenu)
{ {
subMenus.insert(key, subMenu); subMenus.insert(key, subMenu);

View File

@@ -75,7 +75,7 @@ namespace BlackGui::Views
const int c = m_model->update(container, sort); const int c = m_model->update(container, sort);
// resize after real update according to mode // resize after real update according to mode
if (presizeThresholdReached) if (presizeThresholdReached) // cppcheck-suppress knownConditionTrueFalse
{ {
// currently no furhter actions // currently no furhter actions
} }
@@ -83,7 +83,7 @@ namespace BlackGui::Views
{ {
this->resizeToContents(); // mode based resize this->resizeToContents(); // mode based resize
} }
else if (presize && !presizeThresholdReached) else if (presize && !presizeThresholdReached) // cppcheck-suppress knownConditionTrueFalse
{ {
// small amount of data not covered before // small amount of data not covered before
this->fullResizeToContents(); this->fullResizeToContents();

View File

@@ -143,8 +143,7 @@ namespace BlackInput
bool CKeyboardWindows::init() bool CKeyboardWindows::init()
{ {
// cppcheck-suppress knownConditionTrueFalse if (useWindowsHook) // cppcheck-suppress knownConditionTrueFalse
if (useWindowsHook)
{ {
Q_ASSERT_X(g_keyboardWindows == nullptr, "CKeyboardWindows::init", "Windows supports only one keyboard instance. Cannot initialize a second one!"); Q_ASSERT_X(g_keyboardWindows == nullptr, "CKeyboardWindows::init", "Windows supports only one keyboard instance. Cannot initialize a second one!");
g_keyboardWindows = this; g_keyboardWindows = this;

View File

@@ -52,18 +52,18 @@ namespace BlackMisc::Aviation
lights.setBeaconOn(true); lights.setBeaconOn(true);
lights.setNavOn(true); lights.setNavOn(true);
if (gsKts > 5) if (gsKts > 30)
{
// mode taxi
lights.setTaxiOn(true);
lights.setLandingOn(false);
}
else if (gsKts > 30)
{ {
// mode accelaration for takeoff // mode accelaration for takeoff
lights.setTaxiOn(false); lights.setTaxiOn(false);
lights.setLandingOn(true); lights.setLandingOn(true);
} }
else if (gsKts > 5)
{
// mode taxi
lights.setTaxiOn(true);
lights.setLandingOn(false);
}
else else
{ {
// slow movements or parking // slow movements or parking

View File

@@ -748,7 +748,7 @@ namespace BlackMisc::Aviation
if (firstSplit.size() >= 2) if (firstSplit.size() >= 2)
{ {
// format like B789/H-SDE1E2E3FGHIJ2J3J4J5M1RWXY/LB1D1 // format like B789/H-SDE1E2E3FGHIJ2J3J4J5M1RWXY/LB1D1
QString equipment = firstSplit.size() >= 2 ? firstSplit[1] : ""; QString equipment = firstSplit[1];
QStringList split = firstSplit[0].split('/'); QStringList split = firstSplit[0].split('/');
if (split.size() >= 3) if (split.size() >= 3)
{ {

View File

@@ -74,7 +74,7 @@ namespace BlackMisc::Aviation
if ((p3 = CSelcal::validCharacters().indexOf(codeUpper.at(2))) < 0) return false; if ((p3 = CSelcal::validCharacters().indexOf(codeUpper.at(2))) < 0) return false;
if ((p4 = CSelcal::validCharacters().indexOf(codeUpper.at(3))) < 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 >= 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; return true;
} }

View File

@@ -352,7 +352,7 @@ namespace BlackMisc
class BLACKMISC_EXPORT CDataCacheRevision::Session class BLACKMISC_EXPORT CDataCacheRevision::Session
{ {
public: public:
// cppcheck-suppress unusedFunction // cppcheck-suppress missingReturn
Session(const QString &filename) : m_filename(filename) {} Session(const QString &filename) : m_filename(filename) {}
void updateSession(); void updateSession();
const QUuid &uuid() const { return m_uuid; } const QUuid &uuid() const { return m_uuid; }

View File

@@ -380,8 +380,7 @@ namespace BlackMisc
QString p = port.toLower().trimmed(); QString p = port.toLower().trimmed();
if (!p.isEmpty()) if (!p.isEmpty())
{ {
// cppcheck-suppress ignoredReturnValue p.toShort(&ok); // cppcheck-suppress ignoredReturnValue
p.toShort(&ok);
if (!ok) if (!ok)
{ {
p = ""; // was not a number p = ""; // was not a number

View File

@@ -64,7 +64,7 @@ namespace BlackMisc
bool CFileUtils::writeStringToLockedFile(const QString &content, const QString &fileNameAndPath) bool CFileUtils::writeStringToLockedFile(const QString &content, const QString &fileNameAndPath)
{ {
QLockFile lock(fileNameAndPath + ".lock"); QLockFile lock(fileNameAndPath + ".lock");
lock.lock(); if (!lock.lock()) { return false; }
return writeStringToFile(content, fileNameAndPath); return writeStringToFile(content, fileNameAndPath);
} }
@@ -81,7 +81,7 @@ namespace BlackMisc
QString CFileUtils::readLockedFileToString(const QString &fileNameAndPath) QString CFileUtils::readLockedFileToString(const QString &fileNameAndPath)
{ {
QLockFile lock(fileNameAndPath + ".lock"); QLockFile lock(fileNameAndPath + ".lock");
lock.lock(); if (!lock.lock()) { return {}; }
return readFileToString(fileNameAndPath); return readFileToString(fileNameAndPath);
} }

View File

@@ -161,10 +161,9 @@ namespace BlackMisc
if (value.isUndefined()) if (value.isUndefined())
{ {
constexpr bool required = false; //! \fixme add RequiredForJson flag in metaclass system 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 // QLatin1String used instead of QStringLiteral below since the latter causes an internal compiler bug
// in GCC 8 and higher // 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 else
{ {

View File

@@ -86,8 +86,7 @@ namespace BlackMisc
const QString p = this->part(index); const QString p = this->part(index);
if (p.isEmpty()) { return false; } if (p.isEmpty()) { return false; }
bool ok = false; bool ok = false;
// cppcheck-suppress ignoredReturnValue p.toInt(&ok); // cppcheck-suppress ignoredReturnValue
p.toInt(&ok);
return ok; return ok;
} }

View File

@@ -1030,14 +1030,11 @@ namespace BlackMisc::Simulation
} }
const QMultiMap<int, CSimulatorInfo> cps(counts.countPerSimulator()); const QMultiMap<int, CSimulatorInfo> cps(counts.countPerSimulator());
CSimulatorInfo maxSim = cps.last(); CSimulatorInfo maxSim = cps.last();
if (simulatorsRepresented > 0) const int count = cps.lastKey(); // how many elements
const QList<CSimulatorInfo> infoWithMaxValues = cps.values(count); // all with the same counts
for (const CSimulatorInfo &info : infoWithMaxValues)
{ {
const int count = cps.lastKey(); // how many elements maxSim.addSimulator(info);
const QList<CSimulatorInfo> infoWithMaxValues = cps.values(count); // all with the same counts
for (const CSimulatorInfo &info : infoWithMaxValues)
{
maxSim.addSimulator(info);
}
} }
return maxSim; return maxSim;
} }

View File

@@ -148,7 +148,7 @@ namespace BlackMisc::Simulation::FsCommon
if (m_shutdown) { return false; } if (m_shutdown) { return false; }
loadedFiles++; loadedFiles++;
bool s = this->loadFile(fn, rules); bool s = this->loadFile(fn, rules);
if (!s) { this->m_fileListWithProblems.append(fn); } if (!s) { filesWithProblems.append(fn); }
} }
{ {

View File

@@ -498,8 +498,7 @@ namespace BlackSimPlugin::FsCommon
// position // position
const double latCorrectionFactor = 90.0 / (10001750.0 * 65536.0 * 65536.0); const double latCorrectionFactor = 90.0 / (10001750.0 * 65536.0 * 65536.0);
const double lonCorrectionFactor = 360.0 / (65536.0 * 65536.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(); // cppcheck-suppress shadowArgument
CAircraftSituation situation = aircraft.getSituation();
CCoordinateGeodetic position = situation.getPosition(); CCoordinateGeodetic position = situation.getPosition();
CLatitude lat(latitudeRaw * latCorrectionFactor, CAngleUnit::deg()); CLatitude lat(latitudeRaw * latCorrectionFactor, CAngleUnit::deg());
CLongitude lon(longitudeRaw * lonCorrectionFactor, CAngleUnit::deg()); CLongitude lon(longitudeRaw * lonCorrectionFactor, CAngleUnit::deg());

View File

@@ -1214,7 +1214,7 @@ namespace BlackSimPlugin::FsxCommon
verified = true; verified = true;
} }
if (!verified) if (!verified) // cppcheck-suppress knownConditionTrueFalse
{ {
CLogMessage(this).info(u"Disable probes: '%1' failed to relase control") << cs.asString(); CLogMessage(this).info(u"Disable probes: '%1' failed to relase control") << cs.asString();
m_useFsxTerrainProbe = false; m_useFsxTerrainProbe = false;
@@ -2641,8 +2641,7 @@ namespace BlackSimPlugin::FsxCommon
void CSimulatorFsxCommon::traceSendId(const CSimConnectObject &simObject, const QString &functionName, const QString &details, bool forceTrace) void CSimulatorFsxCommon::traceSendId(const CSimConnectObject &simObject, const QString &functionName, const QString &details, bool forceTrace)
{ {
if (!forceTrace && !this->isTracingSendId()) { return; } if (!forceTrace && !this->isTracingSendId()) { return; }
// cppcheck-suppress knownConditionTrueFalse if (MaxSendIdTraces < 1) { return; } // cppcheck-suppress knownConditionTrueFalse
if (MaxSendIdTraces < 1) { return; }
DWORD dwLastId = 0; DWORD dwLastId = 0;
const HRESULT hr = SimConnect_GetLastSentPacketID(m_hSimConnect, &dwLastId); const HRESULT hr = SimConnect_GetLastSentPacketID(m_hSimConnect, &dwLastId);
if (isFailure(hr)) { return; } if (isFailure(hr)) { return; }

View File

@@ -190,7 +190,7 @@ namespace XSwiftBus
return true; return true;
} }
void CDBusDispatcher::dbusRemoveWatch(DBusWatch *watch) void CDBusDispatcher::dbusRemoveWatch(const DBusWatch *watch)
{ {
for (auto it = m_watchers.begin(); it != m_watchers.end();) for (auto it = m_watchers.begin(); it != m_watchers.end();)
{ {

View File

@@ -83,7 +83,7 @@ namespace XSwiftBus
void dispatch(); void dispatch();
dbus_bool_t dbusAddWatch(DBusWatch *watch); dbus_bool_t dbusAddWatch(DBusWatch *watch);
void dbusRemoveWatch(DBusWatch *watch); void dbusRemoveWatch(const DBusWatch *watch);
void dbusWatchToggled(DBusWatch *watch); void dbusWatchToggled(DBusWatch *watch);
dbus_bool_t dbusAddTimeout(DBusTimeout *timeout); dbus_bool_t dbusAddTimeout(DBusTimeout *timeout);

View File

@@ -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) }; 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) void CMenu::handler(void *menuRef, void *itemRef)
{ {
if (menuRef && itemRef) if (menuRef && itemRef)

View File

@@ -980,8 +980,7 @@ namespace XSwiftBus
int h = top - bottom; int h = top - bottom;
x -= left; x -= left;
y -= bottom; 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)); } // 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 (traffic->m_lastMouseX == x && traffic->m_lastMouseY == y && traffic->m_lastMouseX >= 0 && traffic->m_lastMouseY >= 0) 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 // mouse NOT moving, we lost focus or we do NOT move anymore
@@ -1099,8 +1098,7 @@ namespace XSwiftBus
return 0; return 0;
} }
// cppcheck-suppress knownConditionTrueFalse if (DEBUG) // cppcheck-suppress knownConditionTrueFalse
if (DEBUG)
{ {
DEBUG_LOG("Camera: " + pos2String(cameraPosition)); DEBUG_LOG("Camera: " + pos2String(cameraPosition));
DEBUG_LOG("Follow aircraft " + traffic->m_followPlaneViewCallsign + " " + modelName); DEBUG_LOG("Follow aircraft " + traffic->m_followPlaneViewCallsign + " " + modelName);