mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06: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:
@ -5,7 +5,6 @@
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <locale>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
@ -261,8 +260,7 @@ std::string VolumeWAD::GetMakerID(const Partition& partition) const
|
||||
return "00";
|
||||
|
||||
// Some weird channels use 0x0000 in place of the MakerID, so we need a check here
|
||||
const std::locale& c_locale = std::locale::classic();
|
||||
if (!std::isprint(temp[0], c_locale) || !std::isprint(temp[1], c_locale))
|
||||
if (!IsPrintableCharacter(temp[0]) || !IsPrintableCharacter(temp[1]))
|
||||
return "00";
|
||||
|
||||
return DecodeString(temp);
|
||||
|
Reference in New Issue
Block a user