Commit 9b1001b5 authored by Harald Sitter's avatar Harald Sitter 🏳️‍🌈
Browse files

use qbytearray instead of manual memory management

there's no real point to storing the original locale as cstring instead
of in a QBA. it does have the downside that we need to manually free the
string though. also QBA condenses the copy logic (it also was
way too verbose to begin with).

also this is more correct behavior... in the event that the setlocale
query returned nullptr (the request could not be honored) we'll want to
reset to a sane "default". the way to achieve that is by setting an
empty string, and that is precisely the behavior QBA will exhibit as
it's always at least {\0} even when constructed from a nullptr. i.e.
instead of calling `setlocale(..., nullptr)` (which is a query and
pointless) we would now call `setlocale(..., "")` which resets the
category from the process environment.
naturally when we actually got a string back we'll rest to that
parent e4192088
...@@ -95,17 +95,10 @@ int CrashedApplication::signalNumber() const ...@@ -95,17 +95,10 @@ int CrashedApplication::signalNumber() const
QString CrashedApplication::signalName() const QString CrashedApplication::signalName() const
{ {
#if HAVE_STRSIGNAL && defined(Q_OS_UNIX) #if HAVE_STRSIGNAL && defined(Q_OS_UNIX)
const char *oldLocale = std::setlocale(LC_MESSAGES, nullptr); const QByteArray originalLocale(std::setlocale(LC_MESSAGES, nullptr));
char *savedLocale;
if (oldLocale) {
savedLocale = strdup(oldLocale);
} else {
savedLocale = nullptr;
std::setlocale(LC_MESSAGES, "C"); std::setlocale(LC_MESSAGES, "C");
const char *name = strsignal(m_signalNumber); const char *name = strsignal(m_signalNumber);
std::setlocale(LC_MESSAGES, savedLocale); std::setlocale(LC_MESSAGES, /* empty string if we got a nullptr */);
return QString::fromLocal8Bit(name ? name : "Unknown"); return QString::fromLocal8Bit(name ? name : "Unknown");
#else #else
switch (m_signalNumber) { switch (m_signalNumber) {
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment