Skip to content

Commit 7ef0e6e

Browse files
committed
Fix cppcheck warnings
1 parent ac04aa3 commit 7ef0e6e

28 files changed

+45
-53
lines changed

src/blackcore/afv/clients/afvclient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ namespace BlackCore::Afv::Clients
183183
m_connection->connectTo(cid, password, callsign, client,
184184
{ // this is the callback when the connection has been established
185185
this, [=](bool authenticated) {
186-
if (!myself) { return; }
186+
if (!myself) { return; } // cppcheck-suppress knownConditionTrueFalse
187187

188188
// HF stations aliased
189189
const QVector<StationDto> aliasedStations = m_connection->getAllAliasedStations();

src/blackcore/afv/connection/apiserverconnection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace BlackCore::Afv::Connection
6969
{ this, [=](QNetworkReply *nwReply) {
7070
// called in "this" thread
7171
const QScopedPointer<QNetworkReply, QScopedPointerDeleteLater> reply(nwReply);
72-
if (!myself || isShuttingDown()) { return; }
72+
if (!myself || isShuttingDown()) { return; } // cppcheck-suppress knownConditionTrueFalse
7373

7474
this->logRequestDuration(reply.data(), "authentication");
7575
if (reply->error() != QNetworkReply::NoError)
@@ -278,7 +278,7 @@ namespace BlackCore::Afv::Connection
278278
QPointer<CApiServerConnection> myself(this);
279279
this->connectTo(m_username, m_password, m_client, m_networkVersion,
280280
{ this, [=](bool authenticated) {
281-
if (!myself) { return; }
281+
if (!myself) { return; } // cppcheck-suppress knownConditionTrueFalse
282282
CLogMessage(this).info(u"API server authenticated '%1': %2") << m_username << boolToYesNo(authenticated);
283283
} });
284284
}

src/blackcore/afv/connection/clientconnection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace BlackCore::Afv::Connection
5050
{ // callback called when connected
5151
this, [=](bool authenticated) {
5252
// callback when connection has been established
53-
if (!myself) { return; }
53+
if (!myself) { return; } // cppcheck-suppress knownConditionTrueFalse
5454

5555
if (authenticated)
5656
{

src/blackcore/afv/model/afvmapreader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace BlackCore::Afv::Model
3232
{
3333
loop.exec();
3434
}
35-
const QByteArray jsonData = reply->readAll();
35+
const QByteArray jsonData = reply ? reply->readAll() : QByteArray {};
3636
if (reply) { reply->deleteLater(); }
3737

3838
if (jsonData.isEmpty()) { return; }

src/blackcore/airspacemonitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ namespace BlackCore
186186
eventLoop.stopWhen(m_fsdClient, &CFSDClient::flightPlanReceived, [=](const auto &cs, const auto &) { return cs == callsign; });
187187
if (eventLoop.exec(1500))
188188
{
189-
if (!myself || !sApp || sApp->isShuttingDown()) { return CFlightPlan(); }
189+
if (!myself || !sApp || sApp->isShuttingDown()) { return CFlightPlan(); } // cppcheck-suppress knownConditionTrueFalse
190190
if (m_flightPlanCache.contains(callsign))
191191
{
192192
plan = m_flightPlanCache[callsign];

src/blackcore/context/contextsimulatorimpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ namespace BlackCore::Context
644644
if (!m_simulatorPlugin.first.isUnspecified())
645645
{
646646
ISimulator *simulator = m_simulatorPlugin.second;
647-
if (simulator->isConnected())
647+
if (simulator && simulator->isConnected())
648648
{
649649
// we are about to unload an connected simulator
650650
this->updateMarkAllAsNotRendered(); // without plugin nothing can be rendered

src/blackcore/setupreader.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ namespace BlackCore
117117
// "retry" possible in some cases
118118
do
119119
{
120-
if (ignoreCmdBootstrapUrl || !checkCmdBootstrapUrl || CNetworkUtils::canConnect(url, CNetworkUtils::getLongTimeoutMs()))
120+
if (ignoreCmdBootstrapUrl || !checkCmdBootstrapUrl || CNetworkUtils::canConnect(url, CNetworkUtils::getLongTimeoutMs())) // cppcheck-suppress knownConditionTrueFalse
121121
{
122122
ok = true;
123123
break;
@@ -308,7 +308,6 @@ namespace BlackCore
308308
{
309309
Q_ASSERT_X(!(webRead && localRead), Q_FUNC_INFO, "Local and web read together seems to be wrong");
310310
CStatusMessageList msgs;
311-
QPointer<CSetupReader> myself(this);
312311

313312
bool available = false;
314313
if (webRead || localRead)

src/blackgui/components/settingsnetworkserverscomponent.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ namespace BlackGui::Components
9898
else
9999
{
100100
qFatal("Wrong sender");
101-
// cppcheck-suppress duplicateBreak
102101
return;
103102
}
104103

src/blackgui/loadindicator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace BlackGui
6262
if (processEvents && sGui)
6363
{
6464
sGui->processEventsToRefreshGui();
65-
if (!myself) { return -1; } // deleted in meantime (process events)
65+
if (!myself) { return -1; } // cppcheck-suppress knownConditionTrueFalse // deleted in meantime (process events)
6666
}
6767

6868
const int stopId = m_currentId++; // copy

src/blackgui/menus/menuaction.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,11 @@ namespace BlackGui::Menus
534534
}
535535
Q_ASSERT_X(subMenu, Q_FUNC_INFO, "Could not create sub menu");
536536

537-
subMenu->setParent(parentMenu);
537+
if (subMenu)
538+
{
539+
subMenu->setParent(parentMenu);
540+
}
541+
538542
if (pathDepth > 0 && subMenu)
539543
{
540544
subMenus.insert(key, subMenu);

src/blackgui/views/viewbase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ namespace BlackGui::Views
7575
const int c = m_model->update(container, sort);
7676

7777
// resize after real update according to mode
78-
if (presizeThresholdReached)
78+
if (presizeThresholdReached) // cppcheck-suppress knownConditionTrueFalse
7979
{
8080
// currently no furhter actions
8181
}
8282
else if (reallyResize)
8383
{
8484
this->resizeToContents(); // mode based resize
8585
}
86-
else if (presize && !presizeThresholdReached)
86+
else if (presize && !presizeThresholdReached) // cppcheck-suppress knownConditionTrueFalse
8787
{
8888
// small amount of data not covered before
8989
this->fullResizeToContents();

src/blackinput/win/keyboardwindows.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ namespace BlackInput
143143

144144
bool CKeyboardWindows::init()
145145
{
146-
// cppcheck-suppress knownConditionTrueFalse
147-
if (useWindowsHook)
146+
if (useWindowsHook) // cppcheck-suppress knownConditionTrueFalse
148147
{
149148
Q_ASSERT_X(g_keyboardWindows == nullptr, "CKeyboardWindows::init", "Windows supports only one keyboard instance. Cannot initialize a second one!");
150149
g_keyboardWindows = this;

src/blackmisc/aviation/aircraftsituation.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ namespace BlackMisc::Aviation
5252
lights.setBeaconOn(true);
5353
lights.setNavOn(true);
5454

55-
if (gsKts > 5)
56-
{
57-
// mode taxi
58-
lights.setTaxiOn(true);
59-
lights.setLandingOn(false);
60-
}
61-
else if (gsKts > 30)
55+
if (gsKts > 30)
6256
{
6357
// mode accelaration for takeoff
6458
lights.setTaxiOn(false);
6559
lights.setLandingOn(true);
6660
}
61+
else if (gsKts > 5)
62+
{
63+
// mode taxi
64+
lights.setTaxiOn(true);
65+
lights.setLandingOn(false);
66+
}
6767
else
6868
{
6969
// slow movements or parking

src/blackmisc/aviation/flightplan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ namespace BlackMisc::Aviation
748748
if (firstSplit.size() >= 2)
749749
{
750750
// format like B789/H-SDE1E2E3FGHIJ2J3J4J5M1RWXY/LB1D1
751-
QString equipment = firstSplit.size() >= 2 ? firstSplit[1] : "";
751+
QString equipment = firstSplit[1];
752752
QStringList split = firstSplit[0].split('/');
753753
if (split.size() >= 3)
754754
{

src/blackmisc/aviation/selcal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace BlackMisc::Aviation
7474
if ((p3 = CSelcal::validCharacters().indexOf(codeUpper.at(2))) < 0) return false;
7575
if ((p4 = CSelcal::validCharacters().indexOf(codeUpper.at(3))) < 0) return false;
7676
if (p1 >= p2 || p3 >= p4) return false; // pair in alphabetical order
77-
if (p1 == p3 || p2 == p3 || p2 == p4 || p3 == p4) return false; // given letter can be used only once in a SELCAL code
77+
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
7878
return true;
7979
}
8080

src/blackmisc/datacache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ namespace BlackMisc
352352
class BLACKMISC_EXPORT CDataCacheRevision::Session
353353
{
354354
public:
355-
// cppcheck-suppress unusedFunction
355+
// cppcheck-suppress missingReturn
356356
Session(const QString &filename) : m_filename(filename) {}
357357
void updateSession();
358358
const QUuid &uuid() const { return m_uuid; }

src/blackmisc/dbusserver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ namespace BlackMisc
380380
QString p = port.toLower().trimmed();
381381
if (!p.isEmpty())
382382
{
383-
// cppcheck-suppress ignoredReturnValue
384-
p.toShort(&ok);
383+
p.toShort(&ok); // cppcheck-suppress ignoredReturnValue
385384
if (!ok)
386385
{
387386
p = ""; // was not a number

src/blackmisc/fileutils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace BlackMisc
6464
bool CFileUtils::writeStringToLockedFile(const QString &content, const QString &fileNameAndPath)
6565
{
6666
QLockFile lock(fileNameAndPath + ".lock");
67-
lock.lock();
67+
if (!lock.lock()) { return false; }
6868
return writeStringToFile(content, fileNameAndPath);
6969
}
7070

@@ -81,7 +81,7 @@ namespace BlackMisc
8181
QString CFileUtils::readLockedFileToString(const QString &fileNameAndPath)
8282
{
8383
QLockFile lock(fileNameAndPath + ".lock");
84-
lock.lock();
84+
if (!lock.lock()) { return {}; }
8585
return readFileToString(fileNameAndPath);
8686
}
8787

src/blackmisc/mixin/mixinjson.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,9 @@ namespace BlackMisc
161161
if (value.isUndefined())
162162
{
163163
constexpr bool required = false; //! \fixme add RequiredForJson flag in metaclass system
164-
// cppcheck-suppress knownConditionTrueFalse
165164
// QLatin1String used instead of QStringLiteral below since the latter causes an internal compiler bug
166165
// in GCC 8 and higher
167-
if (required) { throw CJsonException(QLatin1String("Missing required member '%1'").arg(member.latin1Name())); }
166+
if (required) { throw CJsonException(QLatin1String("Missing required member '%1'").arg(member.latin1Name())); } // cppcheck-suppress knownConditionTrueFalse
168167
}
169168
else
170169
{

src/blackmisc/simplecommandparser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ namespace BlackMisc
8686
const QString p = this->part(index);
8787
if (p.isEmpty()) { return false; }
8888
bool ok = false;
89-
// cppcheck-suppress ignoredReturnValue
90-
p.toInt(&ok);
89+
p.toInt(&ok); // cppcheck-suppress ignoredReturnValue
9190
return ok;
9291
}
9392

src/blackmisc/simulation/aircraftmodellist.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,14 +1030,11 @@ namespace BlackMisc::Simulation
10301030
}
10311031
const QMultiMap<int, CSimulatorInfo> cps(counts.countPerSimulator());
10321032
CSimulatorInfo maxSim = cps.last();
1033-
if (simulatorsRepresented > 0)
1033+
const int count = cps.lastKey(); // how many elements
1034+
const QList<CSimulatorInfo> infoWithMaxValues = cps.values(count); // all with the same counts
1035+
for (const CSimulatorInfo &info : infoWithMaxValues)
10341036
{
1035-
const int count = cps.lastKey(); // how many elements
1036-
const QList<CSimulatorInfo> infoWithMaxValues = cps.values(count); // all with the same counts
1037-
for (const CSimulatorInfo &info : infoWithMaxValues)
1038-
{
1039-
maxSim.addSimulator(info);
1040-
}
1037+
maxSim.addSimulator(info);
10411038
}
10421039
return maxSim;
10431040
}

src/blackmisc/simulation/fscommon/vpilotrulesreader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ namespace BlackMisc::Simulation::FsCommon
148148
if (m_shutdown) { return false; }
149149
loadedFiles++;
150150
bool s = this->loadFile(fn, rules);
151-
if (!s) { this->m_fileListWithProblems.append(fn); }
151+
if (!s) { filesWithProblems.append(fn); }
152152
}
153153

154154
{

src/plugins/simulator/fscommon/fsuipcimpl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ namespace BlackSimPlugin::FsCommon
498498
// position
499499
const double latCorrectionFactor = 90.0 / (10001750.0 * 65536.0 * 65536.0);
500500
const double lonCorrectionFactor = 360.0 / (65536.0 * 65536.0 * 65536.0 * 65536.0);
501-
// cppcheck-suppress shadowArgument
502-
CAircraftSituation situation = aircraft.getSituation();
501+
CAircraftSituation situation = aircraft.getSituation(); // cppcheck-suppress shadowArgument
503502
CCoordinateGeodetic position = situation.getPosition();
504503
CLatitude lat(latitudeRaw * latCorrectionFactor, CAngleUnit::deg());
505504
CLongitude lon(longitudeRaw * lonCorrectionFactor, CAngleUnit::deg());

src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ namespace BlackSimPlugin::FsxCommon
12141214
verified = true;
12151215
}
12161216

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

src/xswiftbus/dbusdispatcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ namespace XSwiftBus
190190
return true;
191191
}
192192

193-
void CDBusDispatcher::dbusRemoveWatch(DBusWatch *watch)
193+
void CDBusDispatcher::dbusRemoveWatch(const DBusWatch *watch)
194194
{
195195
for (auto it = m_watchers.begin(); it != m_watchers.end();)
196196
{

src/xswiftbus/dbusdispatcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace XSwiftBus
8383
void dispatch();
8484

8585
dbus_bool_t dbusAddWatch(DBusWatch *watch);
86-
void dbusRemoveWatch(DBusWatch *watch);
86+
void dbusRemoveWatch(const DBusWatch *watch);
8787
void dbusWatchToggled(DBusWatch *watch);
8888

8989
dbus_bool_t dbusAddTimeout(DBusTimeout *timeout);

src/xswiftbus/menus.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ namespace XSwiftBus
103103
return { XPLMCreateMenu(name.c_str(), m_data->id, XPLMAppendMenuItem(m_data->id, name.c_str(), nullptr, false), handler, itemsVoidPtr), false, std::move(items) };
104104
}
105105

106+
// cppcheck-suppress constParameter
106107
void CMenu::handler(void *menuRef, void *itemRef)
107108
{
108109
if (menuRef && itemRef)

src/xswiftbus/traffic.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,7 @@ namespace XSwiftBus
980980
int h = top - bottom;
981981
x -= left;
982982
y -= bottom;
983-
// cppcheck-suppress knownConditionTrueFalse
984-
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)); }
983+
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
985984
if (traffic->m_lastMouseX == x && traffic->m_lastMouseY == y && traffic->m_lastMouseX >= 0 && traffic->m_lastMouseY >= 0)
986985
{
987986
// mouse NOT moving, we lost focus or we do NOT move anymore
@@ -1099,8 +1098,7 @@ namespace XSwiftBus
10991098
return 0;
11001099
}
11011100

1102-
// cppcheck-suppress knownConditionTrueFalse
1103-
if (DEBUG)
1101+
if (DEBUG) // cppcheck-suppress knownConditionTrueFalse
11041102
{
11051103
DEBUG_LOG("Camera: " + pos2String(cameraPosition));
11061104
DEBUG_LOG("Follow aircraft " + traffic->m_followPlaneViewCallsign + " " + modelName);

0 commit comments

Comments
 (0)