summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-11-18 12:17:47 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2021-12-02 17:38:33 +0100
commit4ef8e9427c2703146d0b97d16cfdeb2e73185bc8 (patch)
treeb905f1264b6cefe373ba219a7684d39ac68f026b /src
parent4d4aa6e21c3e3a881e87fccda2a6ba545d9190e5 (diff)
Reduce scope of a hack using volatile in favor of viewAt()
We can now get qt_configure_strs to tell us the size of the string, as well as its start, bypassing the strlen()-calling branch of fromLocal8Bit() that caused the need for a hack using a volatile variable. However, QT_CONFIGURE_SETTINGS_PATH still needs the volatile hack. Change-Id: I0181abf512123e6355acdd506d6845c3fb75c0e3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qlibraryinfo.cpp18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp
index c31e1fdecf..0ae41cc48e 100644
--- a/src/corelib/global/qlibraryinfo.cpp
+++ b/src/corelib/global/qlibraryinfo.cpp
@@ -602,24 +602,20 @@ QString QLibraryInfo::path(LibraryPath p)
#endif // settings
if (!fromConf) {
- // "volatile" here is a hack to prevent compilers from doing a
- // compile-time strlen() on "path". The issue is that Qt installers
- // will binary-patch the Qt installation paths -- in such scenarios, Qt
- // will be built with a dummy path, thus the compile-time result of
- // strlen is meaningless.
- const char * volatile path = nullptr;
if (loc == PrefixPath) {
ret = getPrefix();
} else if (int(loc) <= qt_configure_strs.count()) {
- path = qt_configure_strs[loc - 1];
+ ret = QString::fromLocal8Bit(qt_configure_strs.viewAt(loc - 1));
#ifndef Q_OS_WIN // On Windows we use the registry
} else if (loc == SettingsPath) {
- path = QT_CONFIGURE_SETTINGS_PATH;
+ // Use of volatile is a hack to discourage compilers from calling
+ // strlen(), in the inlined fromLocal8Bit(const char *)'s body, at
+ // compile-time, as Qt installers binary-patch the path, replacing
+ // the dummy path seen at compile-time, typically changing length.
+ const char *volatile path = QT_CONFIGURE_SETTINGS_PATH;
+ ret = QString::fromLocal8Bit(path);
#endif
}
-
- if (path)
- ret = QString::fromLocal8Bit(path);
}
if (!ret.isEmpty() && QDir::isRelativePath(ret)) {