mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-14 00:58:51 +02:00
StringUtil: Add IsPrintableCharacter and use it
Add a function that safely returns whether a character is printable i.e. whether 0x20 <= c <= 0x7e is true. This is done in several places in our codebase and it's easy to run into undefined behaviour if the C version defined in <cctype> is used instead of this one, since its behaviour is undefined if the character is not representable as an unsigned char. This fixes MemoryViewWidget.
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/HW/AddressSpace.h"
|
||||
#include "Core/PowerPC/BreakPoints.h"
|
||||
@ -169,8 +170,8 @@ void MemoryViewWidget::Update()
|
||||
case Type::ASCII:
|
||||
update_values([&accessors](u32 address) {
|
||||
const char value = accessors->ReadU8(address);
|
||||
return std::isprint(value) ? QString{QChar::fromLatin1(value)} :
|
||||
QString{QChar::fromLatin1('.')};
|
||||
return IsPrintableCharacter(value) ? QString{QChar::fromLatin1(value)} :
|
||||
QString{QChar::fromLatin1('.')};
|
||||
});
|
||||
break;
|
||||
case Type::U16:
|
||||
|
Reference in New Issue
Block a user