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

@@ -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

View File

@@ -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)
{

View File

@@ -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;
}

View File

@@ -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; }

View File

@@ -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

View File

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

View File

@@ -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
{

View File

@@ -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;
}

View File

@@ -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;
}

View File

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