Skip to content

Commit

Permalink
Fix cppcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ltoenning committed Apr 18, 2023
1 parent ac04aa3 commit 7ef0e6e
Show file tree
Hide file tree
Showing 28 changed files with 45 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/blackcore/afv/clients/afvclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<StationDto> aliasedStations = m_connection->getAllAliasedStations();
Expand Down
4 changes: 2 additions & 2 deletions src/blackcore/afv/connection/apiserverconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace BlackCore::Afv::Connection
{ this, [=](QNetworkReply *nwReply) {
// called in "this" thread
const QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nwReply);
if (!myself || isShuttingDown()) { return; }
if (!myself || isShuttingDown()) { return; } // cppcheck-suppress knownConditionTrueFalse

this->logRequestDuration(reply.data(), "authentication");
if (reply->error() != QNetworkReply::NoError)
Expand Down Expand Up @@ -278,7 +278,7 @@ namespace BlackCore::Afv::Connection
QPointer<CApiServerConnection> 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);
} });
}
Expand Down
2 changes: 1 addition & 1 deletion src/blackcore/afv/connection/clientconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/blackcore/afv/model/afvmapreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion src/blackcore/airspacemonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/blackcore/context/contextsimulatorimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/blackcore/setupreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<CSetupReader> myself(this);

bool available = false;
if (webRead || localRead)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ namespace BlackGui::Components
else
{
qFatal("Wrong sender");
// cppcheck-suppress duplicateBreak
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/blackgui/loadindicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/blackgui/menus/menuaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/blackgui/views/viewbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ 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
}
else if (reallyResize)
{
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();
Expand Down
3 changes: 1 addition & 2 deletions src/blackinput/win/keyboardwindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/blackmisc/aviation/aircraftsituation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/blackmisc/aviation/flightplan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/blackmisc/aviation/selcal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/blackmisc/datacache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
3 changes: 1 addition & 2 deletions src/blackmisc/dbusserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/blackmisc/fileutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
3 changes: 1 addition & 2 deletions src/blackmisc/mixin/mixinjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 1 addition & 2 deletions src/blackmisc/simplecommandparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 4 additions & 7 deletions src/blackmisc/simulation/aircraftmodellist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,14 +1030,11 @@ namespace BlackMisc::Simulation
}
const QMultiMap<int, CSimulatorInfo> cps(counts.countPerSimulator());
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
const QList<CSimulatorInfo> infoWithMaxValues = cps.values(count); // all with the same counts
for (const CSimulatorInfo &info : infoWithMaxValues)
{
maxSim.addSimulator(info);
}
maxSim.addSimulator(info);
}
return maxSim;
}
Expand Down
2 changes: 1 addition & 1 deletion src/blackmisc/simulation/fscommon/vpilotrulesreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
}

{
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/simulator/fscommon/fsuipcimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion src/xswiftbus/dbusdispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();)
{
Expand Down
2 changes: 1 addition & 1 deletion src/xswiftbus/dbusdispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/xswiftbus/menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions src/xswiftbus/traffic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7ef0e6e

Please sign in to comment.