Debugger: Fix crash when showing characters > 0xffff

Change-Id: I8eb1492f7ba9fbe846e18e7e93bd8ca57edf177d
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2022-08-09 16:11:22 +02:00
parent 4c16c221a1
commit 3af72077a0

View File

@@ -73,6 +73,7 @@
#include <QMimeData> #include <QMimeData>
#include <QPainter> #include <QPainter>
#include <QSet> #include <QSet>
#include <QStringDecoder>
#include <QTableWidget> #include <QTableWidget>
#include <QTabWidget> #include <QTabWidget>
#include <QTextEdit> #include <QTextEdit>
@@ -663,6 +664,15 @@ static QString reformatInteger(quint64 value, int format, int size, bool isSigne
// Format printable (char-type) characters // Format printable (char-type) characters
static QString reformatCharacter(int code, int size, bool isSigned) static QString reformatCharacter(int code, int size, bool isSigned)
{ {
if (code > 0xffff) {
std::array<char, sizeof(char32_t)> buf;
memcpy(buf.data(), &code, sizeof(char32_t));
QByteArrayView view(buf);
const QString encoded = QStringDecoder(QStringDecoder::Utf32)(view);
return QString("'%1'\t%2\t0x%3").arg(encoded).arg(unsigned(code)).arg(uint(code & ((1ULL << (8*size)) - 1)),
2 * size, 16, QLatin1Char('0'));
}
QChar c; QChar c;
switch (size) { switch (size) {
case 1: c = QChar(uchar(code)); break; case 1: c = QChar(uchar(code)); break;
@@ -694,6 +704,9 @@ static QString reformatCharacter(int code, int size, bool isSigned)
else else
out += QString(2 + 2 * size, ' '); out += QString(2 + 2 * size, ' ');
} else { } else {
if (size == 2)
out += QString::number(char16_t(code));
else
out += QString::number(unsigned(code)); out += QString::number(unsigned(code));
} }