From 5b6e7aabcff8e96872bfbb9206cd251697fbddb1 Mon Sep 17 00:00:00 2001 From: Matthew Foulds Date: Tue, 19 Nov 2019 18:47:00 +0000 Subject: [PATCH] Fixed 11874 (leading 0s ignored by debugger) --- Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp | 2 +- Source/Core/DolphinQt/Debugger/MemoryWidget.cpp | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp index 86874198af..e33a2a8880 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/MemoryViewWidget.cpp @@ -379,7 +379,7 @@ void MemoryViewWidget::OnCopyHex() u64 value = accessors->ReadU64(addr); QApplication::clipboard()->setText( - QStringLiteral("%1").arg(value, length * 2, 16, QLatin1Char('0')).left(length * 2)); + QStringLiteral("%1").arg(value, sizeof(u64) * 2, 16, QLatin1Char('0')).left(length * 2)); } void MemoryViewWidget::OnContextMenu() diff --git a/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp b/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp index 6de34ebab6..d76e6b0b5a 100644 --- a/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp +++ b/Source/Core/DolphinQt/Debugger/MemoryWidget.cpp @@ -488,12 +488,15 @@ void MemoryWidget::OnSetValue() const QByteArray bytes = m_data_edit->text().toUtf8(); for (char c : bytes) - accessors->WriteU8(static_cast(c), addr++); + accessors->WriteU8(addr++, static_cast(c)); } else { bool good_value; - u64 value = m_data_edit->text().toULongLong(&good_value, 16); + const QString text = m_data_edit->text(); + const int length = + text.startsWith(QStringLiteral("0x"), Qt::CaseInsensitive) ? text.size() - 2 : text.size(); + const u64 value = text.toULongLong(&good_value, 16); if (!good_value) { @@ -501,15 +504,15 @@ void MemoryWidget::OnSetValue() return; } - if (value == static_cast(value)) + if (length <= 2) { accessors->WriteU8(addr, static_cast(value)); } - else if (value == static_cast(value)) + else if (length <= 4) { accessors->WriteU16(addr, static_cast(value)); } - else if (value == static_cast(value)) + else if (length <= 8) { accessors->WriteU32(addr, static_cast(value)); }