Fix cppcheck and compiler warnings

This commit is contained in:
Mat Sutcliffe
2020-06-18 23:48:58 +01:00
parent 9309beefc4
commit 670b1a1986
61 changed files with 131 additions and 153 deletions

View File

@@ -175,6 +175,7 @@ namespace BlackMisc
static_cast<void>(std::initializer_list<int>
{
//! \fixme C-style cast is needed due to a clang bug: https://bugs.llvm.org/show_bug.cgi?id=39375
// cppcheck-suppress accessForwarded
((void)(std::forward<F>(visitor)(std::get<Is * 2>(std::forward<T>(tuple)), std::get<Is * 2 + 1>(std::forward<T>(tuple)))), 0)...
});
}

View File

@@ -495,11 +495,10 @@ namespace BlackMisc
QSet<int> ids;
dir.setFilter(QDir::Files | QDir::NoSymLinks);
dir.setSorting(QDir::Name);
bool ok = false;
for (const QFileInfo &fileInfo : dir.entryInfoList())
{
const QString fn(fileInfo.fileName());
ok = fn.size() > 5;
bool ok = fn.size() > 5;
if (!ok) { continue; }
BLACK_VERIFY_X(ok, Q_FUNC_INFO, "wrong file name");
const int id = fn.leftRef(5).toInt(&ok);

View File

@@ -233,7 +233,7 @@ namespace BlackMisc
{
QMutexLocker lock(&m_mutex);
decltype(m_queue) queue;
qSwap(m_queue, queue);
std::swap(m_queue, queue);
lock.unlock();
for (const auto &pair : BlackMisc::as_const(queue))
@@ -391,13 +391,13 @@ namespace BlackMisc
{
m_originalTimestamps = fromJson(json.value("timestamps").toObject());
QUuid uuid(json.value("uuid").toString());
if (uuid == m_uuid && m_admittedQueue.isEmpty())
QUuid id(json.value("uuid").toString());
if (id == m_uuid && m_admittedQueue.isEmpty())
{
if (m_pendingWrite) { return guard; }
return {};
}
if (updateUuid) { m_uuid = uuid; }
if (updateUuid) { m_uuid = id; }
auto timesToLive = fromJson(json.value("ttl").toObject());
for (auto it = m_originalTimestamps.cbegin(); it != m_originalTimestamps.cend(); ++it)
@@ -807,19 +807,19 @@ namespace BlackMisc
return;
}
auto json = QJsonDocument::fromJson(file.readAll()).object();
QUuid uuid(json.value("uuid").toString());
QUuid id(json.value("uuid").toString());
CSequence<CProcessInfo> apps;
auto status = apps.convertFromJsonNoThrow(json.value("apps").toObject(), this, QStringLiteral("Error in %1 apps object").arg(m_filename));
apps.removeIf([](const CProcessInfo & pi) { return ! pi.exists(); });
if (apps.isEmpty()) { uuid = CIdentifier().toUuid(); }
m_uuid = uuid;
if (apps.isEmpty()) { id = CIdentifier().toUuid(); }
m_uuid = id;
CProcessInfo currentProcess = CProcessInfo::currentProcess();
Q_ASSERT(currentProcess.exists());
apps.replaceOrAdd(currentProcess);
json.insert("apps", apps.toJson());
json.insert("uuid", uuid.toString());
json.insert("uuid", m_uuid.toString());
if (file.seek(0) && file.resize(0) && file.write(QJsonDocument(json).toJson()))
{
if (!file.checkedClose())

View File

@@ -474,6 +474,7 @@ namespace BlackMisc
default:
const QString m = QString("no property, index ").append(index.toQString());
Q_ASSERT_X(false, Q_FUNC_INFO, m.toLocal8Bit().constData());
Q_UNUSED(m)
break;
}
}

View File

@@ -544,7 +544,6 @@ namespace BlackMisc
QJsonObject unwrapCache(const QJsonObject &object)
{
if (object.size() != 1) { return object; } // no cache format
const QString key = object.constBegin().key();
const QJsonObject cacheObject = object.constBegin()->toObject();
if (cacheObject.contains("type") && cacheObject.contains("value"))
{

View File

@@ -252,7 +252,7 @@ namespace BlackMisc
void CTextMessage::toggleSenderRecipient()
{
qSwap(m_senderCallsign, m_recipientCallsign);
std::swap(m_senderCallsign, m_recipientCallsign);
}
bool CTextMessage::isSelcalMessage() const

View File

@@ -48,7 +48,7 @@ namespace BlackMisc
this->push_back(message);
}
CTextMessageList::CTextMessageList(const QString &message, const QList<CFrequency> &frequencies, const BlackMisc::Aviation::CCallsign &fromCallsign)
CTextMessageList::CTextMessageList(const QString &message, const QList<CFrequency> &frequencies, const CCallsign &fromCallsign)
{
if (frequencies.isEmpty()) return;
for (const CFrequency &frequency : frequencies)

View File

@@ -50,13 +50,13 @@ namespace BlackMisc
CTextMessageList(const QString &message, const Aviation::CCallsign &senderCallsign, const Aviation::CCallsign &recipientCallsign);
//! Constructor, single radio message
CTextMessageList(const QString &message, const PhysicalQuantities::CFrequency &frequency, const Aviation::CCallsign &senderCallsign = Aviation::CCallsign());
CTextMessageList(const QString &message, const PhysicalQuantities::CFrequency &frequency, const Aviation::CCallsign &senderCallsign = {});
//! Constructor, single message
CTextMessageList(const CTextMessage &message);
//! Constructor, multi-frequency radio messages
CTextMessageList(const QString &message, const QList<PhysicalQuantities::CFrequency> &frequencies, const Aviation::CCallsign &sender = Aviation::CCallsign());
CTextMessageList(const QString &message, const QList<PhysicalQuantities::CFrequency> &frequencies, const Aviation::CCallsign &fromCallsign = {});
//! Construct from a base class object.
CTextMessageList(const CSequence<CTextMessage> &other);

View File

@@ -633,15 +633,15 @@ namespace BlackMisc
// make absolute
if (!soPath.left(3).contains(':')) { soPath = CFileUtils::appendFilePaths(relPath, soPath); }
const QDir p(soPath); // always absolute path now
if (checked && !p.exists())
const QDir dir(soPath); // always absolute path now
if (checked && !dir.exists())
{
// skip, not existing
if (logConfigPathReading()) { CLogMessage(getLogCategories()).info(u"FSX SimObjects path skipped, not existing: '%1' in '%2'") << p.absolutePath() << fsxFile; }
if (logConfigPathReading()) { CLogMessage(getLogCategories()).info(u"FSX SimObjects path skipped, not existing: '%1' in '%2'") << dir.absolutePath() << fsxFile; }
continue;
}
const QString afp = p.absolutePath().toLower();
const QString afp = dir.absolutePath().toLower();
if (!CDirectoryUtils::containsFileInDir(afp, airFileFilter(), true))
{
if (logConfigPathReading()) { CLogMessage(getLogCategories()).info(u"FSX SimObjects path: Skipping '%1' from '%2', no '%3' file") << afp << fsxFile << airFileFilter(); }

View File

@@ -302,7 +302,7 @@ namespace BlackMisc
}
else
{
const qint64 diff = noSituation ? -1 : m_currentTimeMsSinceEpoch - currentSituation.getAdjustedMSecsSinceEpoch();
const qint64 diff = m_currentTimeMsSinceEpoch - currentSituation.getAdjustedMSecsSinceEpoch();
m = CStatusMessage(this).warning(u"Invalid situation, diff. %1ms #%2 for interpolation reported for '%3' (Interpolant: %4 interpolation: %5)") <<
diff << m_invalidSituations << m_callsign.asString() << boolToTrueFalse(isValidInterpolant) << boolToTrueFalse(isValidInterpolation);
}
@@ -609,10 +609,10 @@ namespace BlackMisc
}
else
{
CAircraftModel model = this->getAircraftInRangeForCallsign(m_callsign).getModel();
if (model.hasModelString())
CAircraftModel foundModel = this->getAircraftInRangeForCallsign(m_callsign).getModel();
if (foundModel.hasModelString())
{
m_model = model;
m_model = foundModel;
}
}
this->getAndFetchModelCG(model.getCG());

View File

@@ -126,7 +126,7 @@ namespace BlackMisc
return true;
}
bool CSimulatorSettings::setRecordedGndRadius(CLength &radius)
bool CSimulatorSettings::setRecordedGndRadius(const CLength &radius)
{
if (radius == m_recordedGndRadius) { return false; }
m_recordedGndRadius = radius;

View File

@@ -124,7 +124,7 @@ namespace BlackMisc
BlackMisc::PhysicalQuantities::CLength getRecordedGndRadius() const { return m_recordedGndRadius; }
//! Record GND values with radius
bool setRecordedGndRadius(BlackMisc::PhysicalQuantities::CLength &radius);
bool setRecordedGndRadius(const BlackMisc::PhysicalQuantities::CLength &radius);
//! Reset the paths
void resetPaths();

View File

@@ -575,15 +575,15 @@ namespace BlackMisc
return false;
}
QFileInfo fileInfo(absoluteTexPath);
if (!fileInfo.exists())
QFileInfo texFileInfo(absoluteTexPath);
if (!texFileInfo.exists())
{
const CStatusMessage m = CStatusMessage(this).error(u"%1/xsb_aircraft.txt Line %2 : Texture '%3' does not exist.") << path << lineNum << absoluteTexPath;
m_loadingMessages.push_back(m);
return false;
}
package.planes.back().textureName = fileInfo.completeBaseName();
package.planes.back().textureName = texFileInfo.completeBaseName();
}
return true;
}