aldelaro5 / dolphin-memory-engine

A RAM search made specifically to search, monitor and edit the Dolphin emulator's emulated memory
MIT License
171 stars 39 forks source link

Convert to `unsigned char` before invoking `std::isprint()`. #174

Closed cristian64 closed 3 months ago

cristian64 commented 3 months ago

As the documentation states, the caller must check that the input character in std::isprint() is a valid unsigned char:

Like all other functions from <cctype>, the behavior of std::isprint is undefined if the argument's value is neither representable as unsigned char nor equal to EOF. To use these functions safely with plain chars (or signed chars), the argument should first be converted to unsigned char:

bool my_isprint(char ch)
{
    return std::isprint(static_cast<unsigned char>(ch));
}

The aforementioned undefined behavior manifests as a debug assertion when compiled with MSVC:

image

The affected functionality was introduced in #122.

Fixes #173.

dreamsyntax commented 3 months ago

Thanks, beat me to it