summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-11-14 11:26:27 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-12-12 08:22:51 +0000
commitf640dd08ca46c8657aab38d0c3d5dc350b0035cd (patch)
tree03bc123e15119eecc9f3af36464a55963b5093b2
parent7301cd2df11d07eb58cbfb443348e31c86a00ccf (diff)
windeployqt: Fix some Clang warnings
- Use range-based for - Remove else after return - Use member initialization - Dubious check of bool * - Prefer static QFileInfo::exists() - Use uninitialized struct QJsonParseError Change-Id: If2705d6829ba3186cafb068a2c083943d33d1c66 Reviewed-by: Andre de la Rocha <andre.rocha@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
-rw-r--r--src/shared/winutils/qmlutils.cpp4
-rw-r--r--src/shared/winutils/qmlutils.h3
-rw-r--r--src/shared/winutils/utils.cpp6
-rw-r--r--src/windeployqt/main.cpp75
4 files changed, 39 insertions, 49 deletions
diff --git a/src/shared/winutils/qmlutils.cpp b/src/shared/winutils/qmlutils.cpp
index 6fe77e64f..e66d30554 100644
--- a/src/shared/winutils/qmlutils.cpp
+++ b/src/shared/winutils/qmlutils.cpp
@@ -51,7 +51,7 @@ QString QmlImportScanResult::Module::installPath(const QString &root) const
const int lastSlashPos = relativePath.lastIndexOf(QLatin1Char('/'));
if (lastSlashPos != -1) {
result += QLatin1Char('/');
- result += relativePath.left(lastSlashPos);
+ result += relativePath.leftRef(lastSlashPos);
}
return result;
}
@@ -114,7 +114,7 @@ QmlImportScanResult runQmlImportScanner(const QString &directory, const QString
+ QStringLiteral(": ") + QString::fromLocal8Bit(stdErr);
return result;
}
- QJsonParseError jsonParseError;
+ QJsonParseError jsonParseError{};
const QJsonDocument data = QJsonDocument::fromJson(stdOut, &jsonParseError);
if (data.isNull() ) {
*errorMessage = binary + QStringLiteral(" returned invalid JSON output: ")
diff --git a/src/shared/winutils/qmlutils.h b/src/shared/winutils/qmlutils.h
index 895c7f1de..267f6d92a 100644
--- a/src/shared/winutils/qmlutils.h
+++ b/src/shared/winutils/qmlutils.h
@@ -47,10 +47,9 @@ struct QmlImportScanResult {
QString relativePath;
};
- QmlImportScanResult() : ok(false) {}
void append(const QmlImportScanResult &other);
- bool ok;
+ bool ok = false;
QList<Module> modules;
QStringList plugins;
};
diff --git a/src/shared/winutils/utils.cpp b/src/shared/winutils/utils.cpp
index 195d8efd5..00a205438 100644
--- a/src/shared/winutils/utils.cpp
+++ b/src/shared/winutils/utils.cpp
@@ -493,8 +493,6 @@ QString findInPath(const QString &file)
const char *qmakeInfixKey = "QT_INFIX";
-QMap<QString, QString> queryQMakeAll(QString *errorMessage);
-
QMap<QString, QString> queryQMakeAll(QString *errorMessage)
{
QByteArray stdOut;
@@ -819,12 +817,12 @@ inline void determineDebugAndDependentLibs(const ImageNtHeader *nth, const void
{
const bool hasDebugEntry = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
QStringList dependentLibraries;
- if (dependentLibrariesIn || (isDebugIn && hasDebugEntry && !isMinGW))
+ if (dependentLibrariesIn || (isDebugIn != nullptr && hasDebugEntry && !isMinGW))
dependentLibraries = readImportSections(nth, fileMemory, errorMessage);
if (dependentLibrariesIn)
*dependentLibrariesIn = dependentLibraries;
- if (isDebugIn) {
+ if (isDebugIn != nullptr) {
if (isMinGW) {
// Use logic that's used e.g. in objdump / pfd library
*isDebugIn = !(nth->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED);
diff --git a/src/windeployqt/main.cpp b/src/windeployqt/main.cpp
index e9823bb16..de5238fdc 100644
--- a/src/windeployqt/main.cpp
+++ b/src/windeployqt/main.cpp
@@ -181,12 +181,11 @@ static inline QString webProcessBinary(const char *binaryName, Platform p)
static QByteArray formatQtModules(quint64 mask, bool option = false)
{
QByteArray result;
- const size_t qtModulesCount = sizeof(qtModuleEntries)/sizeof(QtModuleEntry);
- for (size_t i = 0; i < qtModulesCount; ++i) {
- if (mask & qtModuleEntries[i].module) {
+ for (const auto &qtModule : qtModuleEntries) {
+ if (mask & qtModule.module) {
if (!result.isEmpty())
result.append(' ');
- result.append(option ? qtModuleEntries[i].option : qtModuleEntries[i].libraryName);
+ result.append(option ? qtModule.option : qtModule.libraryName);
}
}
return result;
@@ -830,10 +829,9 @@ static const PluginModuleMapping pluginModuleMappings[] =
static inline quint64 qtModuleForPlugin(const QString &subDirName)
{
- const PluginModuleMapping *end = pluginModuleMappings
- + sizeof(pluginModuleMappings) / sizeof(pluginModuleMappings[0]);
- const PluginModuleMapping *result =
- std::find_if(pluginModuleMappings, end,
+ const auto end = std::end(pluginModuleMappings);
+ const auto result =
+ std::find_if(std::begin(pluginModuleMappings), end,
[&subDirName] (const PluginModuleMapping &m) { return subDirName == QLatin1String(m.directoryName); });
return result != end ? result->module : 0; // "designer"
}
@@ -852,12 +850,11 @@ static quint64 qtModule(QString module, const QString &infix)
if (endPos > 0)
module.truncate(endPos);
// That should leave us with 'Qt5Core<d>'.
- const size_t qtModulesCount = sizeof(qtModuleEntries)/sizeof(QtModuleEntry);
- for (size_t i = 0; i < qtModulesCount; ++i) {
- const QLatin1String libraryName(qtModuleEntries[i].libraryName);
+ for (const auto &qtModule : qtModuleEntries) {
+ const QLatin1String libraryName(qtModule.libraryName);
if (module == libraryName
|| (module.size() == libraryName.size() + 1 && module.startsWith(libraryName))) {
- return qtModuleEntries[i].module;
+ return qtModule.module;
}
}
return 0;
@@ -946,10 +943,9 @@ QStringList findQtPlugins(quint64 *usedQtModules, quint64 disabledQtModules,
static QStringList translationNameFilters(quint64 modules, const QString &prefix)
{
QStringList result;
- const size_t qtModulesCount = sizeof(qtModuleEntries)/sizeof(QtModuleEntry);
- for (size_t i = 0; i < qtModulesCount; ++i) {
- if ((qtModuleEntries[i].module & modules) && qtModuleEntries[i].translation) {
- const QString name = QLatin1String(qtModuleEntries[i].translation) +
+ for (const auto &qtModule : qtModuleEntries) {
+ if ((qtModule.module & modules) && qtModule.translation) {
+ const QString name = QLatin1String(qtModule.translation) +
QLatin1Char('_') + prefix + QStringLiteral(".qm");
if (!result.contains(name))
result.push_back(name);
@@ -1096,9 +1092,8 @@ static QStringList compilerRunTimeLibs(Platform platform, bool isDebug, unsigned
const QString binPath = QFileInfo(gcc).absolutePath();
QStringList filters;
const QString suffix = QLatin1Char('*') + sharedLibrarySuffix(platform);
- const size_t count = sizeof(minGwRuntimes) / sizeof(minGwRuntimes[0]);
- for (size_t i = 0; i < count; ++i)
- filters.append(QLatin1String(minGwRuntimes[i]) + suffix);
+ for (auto minGwRuntime : minGwRuntimes)
+ filters.append(QLatin1String(minGwRuntime) + suffix);
const QFileInfoList &dlls = QDir(binPath).entryInfoList(filters, QDir::Files);
for (const QFileInfo &dllFi : dlls)
result.append(dllFi.absoluteFilePath());
@@ -1341,12 +1336,11 @@ static DeployResult deploy(const Options &options,
// Apply options flags and re-add library names.
QString qtGuiLibrary;
- const size_t qtModulesCount = sizeof(qtModuleEntries)/sizeof(QtModuleEntry);
- for (size_t i = 0; i < qtModulesCount; ++i) {
- if (result.deployedQtLibraries & qtModuleEntries[i].module) {
- const QString library = libraryPath(libraryLocation, qtModuleEntries[i].libraryName, qtLibInfix, options.platform, isDebug);
+ for (const auto &qtModule : qtModuleEntries) {
+ if (result.deployedQtLibraries & qtModule.module) {
+ const QString library = libraryPath(libraryLocation, qtModule.libraryName, qtLibInfix, options.platform, isDebug);
deployedQtLibraries.append(library);
- if (qtModuleEntries[i].module == QtGuiModule)
+ if (qtModule.module == QtGuiModule)
qtGuiLibrary = library;
}
}
@@ -1383,7 +1377,7 @@ static DeployResult deploy(const Options &options,
if (options.angleDetection != Options::AngleDetectionForceOff
&& (dependsOnAngle || dependsOnCombinedAngle || !dependsOnOpenGl || options.angleDetection == Options::AngleDetectionForceOn)) {
const QString combinedAngleFullPath = qtBinDir + slash + libCombinedQtAngleName;
- if (QFileInfo(combinedAngleFullPath).exists()) {
+ if (QFileInfo::exists(combinedAngleFullPath)) {
deployedQtLibraries.append(combinedAngleFullPath);
} else {
const QString libGlesFullPath = qtBinDir + slash + libGlesName;
@@ -1577,8 +1571,8 @@ static bool deployWebEngineCore(const QMap<QString, QString> &qmakeVariables,
const QString resourcesTargetDir(options.directory + resourcesSubDir);
if (!createDirectory(resourcesTargetDir, errorMessage))
return false;
- for (size_t i = 0; i < sizeof(installDataFiles)/sizeof(installDataFiles[0]); ++i) {
- if (!updateFile(resourcesSourceDir + QLatin1String(installDataFiles[i]),
+ for (auto installDataFile : installDataFiles) {
+ if (!updateFile(resourcesSourceDir + QLatin1String(installDataFile),
resourcesTargetDir, options.updateFileFlags, options.json, errorMessage)) {
return false;
}
@@ -1595,21 +1589,20 @@ static bool deployWebEngineCore(const QMap<QString, QString> &qmakeVariables,
return createDirectory(options.translationsDirectory, errorMessage)
&& updateFile(translations.absoluteFilePath(), options.translationsDirectory,
options.updateFileFlags, options.json, errorMessage);
- } else {
- // Translations have been turned off, but QtWebEngine needs at least one.
- const QFileInfo enUSpak(translations.filePath() + QStringLiteral("/en-US.pak"));
- if (!enUSpak.exists()) {
- std::wcerr << "Warning: Cannot find "
- << QDir::toNativeSeparators(enUSpak.absoluteFilePath()) << ".\n";
- return true;
- }
- const QString webEngineTranslationsDir = options.translationsDirectory + QLatin1Char('/')
- + translations.fileName();
- if (!createDirectory(webEngineTranslationsDir, errorMessage))
- return false;
- return updateFile(enUSpak.absoluteFilePath(), webEngineTranslationsDir,
- options.updateFileFlags, options.json, errorMessage);
}
+ // Translations have been turned off, but QtWebEngine needs at least one.
+ const QFileInfo enUSpak(translations.filePath() + QStringLiteral("/en-US.pak"));
+ if (!enUSpak.exists()) {
+ std::wcerr << "Warning: Cannot find "
+ << QDir::toNativeSeparators(enUSpak.absoluteFilePath()) << ".\n";
+ return true;
+ }
+ const QString webEngineTranslationsDir = options.translationsDirectory + QLatin1Char('/')
+ + translations.fileName();
+ if (!createDirectory(webEngineTranslationsDir, errorMessage))
+ return false;
+ return updateFile(enUSpak.absoluteFilePath(), webEngineTranslationsDir,
+ options.updateFileFlags, options.json, errorMessage);
}
int main(int argc, char **argv)