mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-13 00:58:29 +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:
@ -71,7 +71,7 @@ std::string HexDump(const u8* data, size_t size)
|
||||
if (row_start + i < size)
|
||||
{
|
||||
char c = static_cast<char>(data[row_start + i]);
|
||||
out += std::isprint(c, std::locale::classic()) ? c : '.';
|
||||
out += IsPrintableCharacter(c) ? c : '.';
|
||||
}
|
||||
}
|
||||
out += "\n";
|
||||
|
Reference in New Issue
Block a user