From 89b0ab2d22db510e799e6f9619e8c8e0678f13ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Mon, 30 Dec 2019 10:48:11 +0100 Subject: 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 is used instead of this one, since its behaviour is undefined if the character is not representable as an unsigned char. This fixes MemoryViewWidget. --- Source/Core/Common/StringUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/Common/StringUtil.cpp') diff --git a/Source/Core/Common/StringUtil.cpp b/Source/Core/Common/StringUtil.cpp index 2369208f45..ac7e32efcf 100644 --- a/Source/Core/Common/StringUtil.cpp +++ b/Source/Core/Common/StringUtil.cpp @@ -71,7 +71,7 @@ std::string HexDump(const u8* data, size_t size) if (row_start + i < size) { char c = static_cast(data[row_start + i]); - out += std::isprint(c, std::locale::classic()) ? c : '.'; + out += IsPrintableCharacter(c) ? c : '.'; } } out += "\n"; -- cgit v1.2.3