From 61fc8e1586978b4114139208a9ea440143dffd59 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 14 Jun 2022 01:28:13 +0300 Subject: [PATCH] check if the canonical library/plugin paths are empty Signed-off-by: Ivailo Monev --- src/core/kernel/qcoreapplication.cpp | 30 ++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/core/kernel/qcoreapplication.cpp b/src/core/kernel/qcoreapplication.cpp index 3a401a13a..0679109b7 100644 --- a/src/core/kernel/qcoreapplication.cpp +++ b/src/core/kernel/qcoreapplication.cpp @@ -1640,7 +1640,10 @@ QStringList QCoreApplication::libraryPaths() } foreach (const QString &it, qGetEnvList("LD_LIBRARY_PATH")) { - QString canonicalPath = QDir(it).canonicalPath(); + const QString canonicalPath = QDir(it).canonicalPath(); + if (canonicalPath.isEmpty()) { + continue; + } if (!coreappdata()->app_librarypaths.contains(canonicalPath)) { coreappdata()->app_librarypaths.append(canonicalPath); } @@ -1672,14 +1675,15 @@ void QCoreApplication::setLibraryPaths(const QStringList &paths) */ void QCoreApplication::addLibraryPath(const QString &path) { - if (path.isEmpty()) + const QString canonicalPath = QDir(path).canonicalPath(); + if (canonicalPath.isEmpty()) { return; + } // make sure that library paths is initialized libraryPaths(); QMutexLocker locker(qGlobalAppPathsMutex()); - QString canonicalPath = QDir(path).canonicalPath(); if (!coreappdata()->app_librarypaths.contains(canonicalPath)) { coreappdata()->app_librarypaths.prepend(canonicalPath); } @@ -1693,14 +1697,15 @@ void QCoreApplication::addLibraryPath(const QString &path) */ void QCoreApplication::removeLibraryPath(const QString &path) { - if (path.isEmpty()) + const QString canonicalPath = QDir(path).canonicalPath(); + if (canonicalPath.isEmpty()) { return; + } // make sure that library paths is initialized libraryPaths(); QMutexLocker locker(qGlobalAppPathsMutex()); - QString canonicalPath = QDir(path).canonicalPath(); coreappdata()->app_librarypaths.removeAll(canonicalPath); } @@ -1730,7 +1735,10 @@ QStringList QCoreApplication::pluginPaths() } foreach (const QString &it, qGetEnvList("QT_PLUGIN_PATH")) { - QString canonicalPath = QDir(it).canonicalPath(); + const QString canonicalPath = QDir(it).canonicalPath(); + if (canonicalPath.isEmpty()) { + continue; + } if (!coreappdata()->app_pluginpaths.contains(canonicalPath)) { coreappdata()->app_pluginpaths.append(canonicalPath); } @@ -1764,14 +1772,15 @@ void QCoreApplication::setPluginPaths(const QStringList &paths) */ void QCoreApplication::addPluginPath(const QString &path) { - if (path.isEmpty()) + const QString canonicalPath = QDir(path).canonicalPath(); + if (canonicalPath.isEmpty()) { return; + } // make sure that plugin paths is initialized pluginPaths(); QMutexLocker locker(qGlobalAppPathsMutex()); - QString canonicalPath = QDir(path).canonicalPath(); if (!coreappdata()->app_pluginpaths.contains(canonicalPath)) { coreappdata()->app_pluginpaths.prepend(canonicalPath); locker.unlock(); @@ -1787,14 +1796,15 @@ void QCoreApplication::addPluginPath(const QString &path) */ void QCoreApplication::removePluginPath(const QString &path) { - if (path.isEmpty()) + const QString canonicalPath = QDir(path).canonicalPath(); + if (canonicalPath.isEmpty()) { return; + } // make sure that plugin paths is initialized pluginPaths(); QMutexLocker locker(qGlobalAppPathsMutex()); - QString canonicalPath = QDir(path).canonicalPath(); coreappdata()->app_pluginpaths.removeAll(canonicalPath); QFactoryLoader::refreshAll(); }