From 4ef8e9427c2703146d0b97d16cfdeb2e73185bc8 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 18 Nov 2021 12:17:47 +0100 Subject: [PATCH] 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 --- src/corelib/global/qlibraryinfo.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index c31e1fdecfd..0ae41cc48e7 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)) {