mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 09:09:52 -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:
@ -4,9 +4,9 @@
|
||||
|
||||
#include "Core/Core.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cstring>
|
||||
#include <locale>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
@ -31,6 +31,7 @@
|
||||
#include "Common/MemoryUtil.h"
|
||||
#include "Common/MsgHandler.h"
|
||||
#include "Common/ScopeGuard.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Common/Thread.h"
|
||||
#include "Common/Timer.h"
|
||||
#include "Common/Version.h"
|
||||
@ -160,11 +161,8 @@ void DisplayMessage(std::string message, int time_in_ms)
|
||||
return;
|
||||
|
||||
// Actually displaying non-ASCII could cause things to go pear-shaped
|
||||
for (const char& c : message)
|
||||
{
|
||||
if (!std::isprint(c, std::locale::classic()))
|
||||
return;
|
||||
}
|
||||
if (!std::all_of(message.begin(), message.end(), IsPrintableCharacter))
|
||||
return;
|
||||
|
||||
Host_UpdateTitle(message);
|
||||
OSD::AddMessage(std::move(message), time_in_ms);
|
||||
|
Reference in New Issue
Block a user