From 4541fc869188c510db79705ef6981dfe74cf8cf7 Mon Sep 17 00:00:00 2001 From: Matthias <github@mpuchner.de> Date: Tue, 8 Dec 2020 21:07:13 +0100 Subject: [PATCH] fix mem access error which caused the malformed string GUIHelpers::Error::what() returned a char* to a temporary QByteArray which is invalid after leaving what() --- GUI/coregui/utils/GUIHelpers.cpp | 2 +- GUI/coregui/utils/GUIHelpers.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/GUI/coregui/utils/GUIHelpers.cpp b/GUI/coregui/utils/GUIHelpers.cpp index 786393ea8cf..5c426897752 100644 --- a/GUI/coregui/utils/GUIHelpers.cpp +++ b/GUI/coregui/utils/GUIHelpers.cpp @@ -45,7 +45,7 @@ namespace GUIHelpers { Error::~Error() noexcept = default; const char* Error::what() const noexcept { - return message.toLatin1().data(); + return m_messageAsLatin1.data(); } void information(QWidget* parent, const QString& title, const QString& text, diff --git a/GUI/coregui/utils/GUIHelpers.h b/GUI/coregui/utils/GUIHelpers.h index 752f888f7c3..ce5f048f5d5 100644 --- a/GUI/coregui/utils/GUIHelpers.h +++ b/GUI/coregui/utils/GUIHelpers.h @@ -26,7 +26,7 @@ class RealDataItem; namespace GUIHelpers { class Error : public std::exception { public: - explicit Error(const QString& message) noexcept : message(message) {} + explicit Error(const QString& message) noexcept : m_messageAsLatin1(message.toLatin1()) {} virtual ~Error() noexcept; Error(const Error&) = default; @@ -37,7 +37,7 @@ public: const char* what() const noexcept override; private: - QString message; + QByteArray m_messageAsLatin1; }; void information(QWidget* parent, const QString& title, const QString& text, -- GitLab