From 0826aeddd27bf679a0f16799efc69288058edeaf Mon Sep 17 00:00:00 2001 From: Mikhail Svetkin Date: Mon, 16 Jul 2018 16:18:05 +0200 Subject: [PATCH] qlibrary_unix: work around compile bug in gcc5.4 GCC5.4 generates incorrect code. The QString object which is passed by value to f-lambda, has been corrupted by the time this lambda returns. Accessing this object causes memory corruption. The same can be reproduced with std::list and std::string Task-number: QTBUG-69394 Change-Id: I22522d2ddd1d5226de0aff378133d18391e370de Reviewed-by: Gatis Paeglis Reviewed-by: Thiago Macieira --- src/corelib/plugin/qlibrary_unix.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp index 7ffd1369b9..851b9ff82f 100644 --- a/src/corelib/plugin/qlibrary_unix.cpp +++ b/src/corelib/plugin/qlibrary_unix.cpp @@ -182,21 +182,23 @@ bool QLibraryPrivate::load_sys() #if defined(Q_PROCESSOR_X86) && !defined(Q_OS_DARWIN) if (qCpuHasFeature(ArchHaswell)) { - auto transform = [](QStringList &list, QString (*f)(QString)) { + auto transform = [](QStringList &list, void (*f)(QString *)) { QStringList tmp; qSwap(tmp, list); list.reserve(tmp.size() * 2); for (const QString &s : qAsConst(tmp)) { - list.append(f(s)); + QString modifiedPath = s; + f(&modifiedPath); + list.append(modifiedPath); list.append(s); } }; if (pluginState == IsAPlugin) { // add ".avx2" to each suffix in the list - transform(suffixes, [](QString s) { return s.append(QLatin1String(".avx2")); }); + transform(suffixes, [](QString *s) { s->append(QLatin1String(".avx2")); }); } else { // prepend "haswell/" to each prefix in the list - transform(prefixes, [](QString s) { return s.prepend(QLatin1String("haswell/")); }); + transform(prefixes, [](QString *s) { s->prepend(QLatin1String("haswell/")); }); } } #endif