diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-02-04 00:56:01 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-02-05 07:26:55 +0100 |
commit | 4d8cbf9863e5d6fffccc2c0a4adbd279fd4bae89 (patch) | |
tree | f207461dc867036235f6bb6f265c9544db836798 /src/corelib/global/qlibraryinfo.cpp | |
parent | 64de057ebe8c4a2a0ee1ede834a67508cd4f81b1 (diff) |
QLibraryInfo: de-duplicate QT_BUILD_STR
The string was used as the return value of QLibraryInfo::build() and
also string-pasted into the format string in qt_core_boilerplate(). As
a proper substring (not suffix) of the format string, QT_BUILD_STR
could not be shared among the two users.
Fix by interpolating QT_BUILD_STR into the format string, so
QT_BUILD_STR appears by itself in both functions. The string should
now be shared, but compilers have quite low limits on lengths of
strings they will share, so turn the macro into an static function so
the actual string literal appears only once, guaranteeing
de-duplication.
It also feels a bit safer to interpolate the build string instead of
pasting it into the format string; it's not immediately obvious that
it cannot contain %s itself, even if we could expect a compiler
warning in that case.
Change-Id: I69d90c37c3a3dcf8ac46d4f36e7c0d2cf3b947af
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global/qlibraryinfo.cpp')
-rw-r--r-- | src/corelib/global/qlibraryinfo.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index dc19ec0b98..52d967ef37 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -270,7 +270,10 @@ QLibraryInfo::QLibraryInfo() #else # define SHARED_STRING " static" #endif -#define QT_BUILD_STR "Qt " QT_VERSION_STR " (" ARCH_FULL SHARED_STRING DEBUG_STRING " build; by " COMPILER_STRING ")" +static const char *qt_build_string() noexcept +{ + return "Qt " QT_VERSION_STR " (" ARCH_FULL SHARED_STRING DEBUG_STRING " build; by " COMPILER_STRING ")"; +} /*! Returns a string describing how this version of Qt was built. @@ -282,7 +285,7 @@ QLibraryInfo::QLibraryInfo() const char *QLibraryInfo::build() noexcept { - return QT_BUILD_STR; + return qt_build_string(); } /*! @@ -741,13 +744,14 @@ extern const char qt_core_interpreter[] __attribute__((section(".interp"))) extern "C" void qt_core_boilerplate() __attribute__((force_align_arg_pointer)); void qt_core_boilerplate() { - printf("This is the QtCore library version " QT_BUILD_STR "\n" + printf("This is the QtCore library version %s\n" "Copyright (C) 2016 The Qt Company Ltd.\n" "Contact: http://www.qt.io/licensing/\n" "\n" "Installation prefix: %s\n" "Library path: %s\n" "Plugin path: %s\n", + QT_PREPEND_NAMESPACE(qt_build_string)(), QT_CONFIGURE_PREFIX_PATH, qt_configure_strs[QT_PREPEND_NAMESPACE(QLibraryInfo)::LibrariesPath - 1], qt_configure_strs[QT_PREPEND_NAMESPACE(QLibraryInfo)::PluginsPath - 1]); |