mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-27 22:15:49 +00:00
Remove undefined behavior from <ctype.h> calls:
For the functions defined in <ctype.h> the C standard requires that the value of the int argument be in the range of an unsigned char, or be EOF. Violation of this requirement results in undefined behavior.
This commit is contained in:
committed by
Nikolaos D. Bougalis
parent
02c487348a
commit
b4e1b3c1b1
@@ -354,19 +354,19 @@ public:
|
||||
*/
|
||||
bool SetHex (const char* psz, bool bStrict = false)
|
||||
{
|
||||
// Find beginning.
|
||||
auto pBegin = reinterpret_cast<const unsigned char*>(psz);
|
||||
// skip leading spaces
|
||||
if (!bStrict)
|
||||
while (isspace (*psz))
|
||||
psz++;
|
||||
while (isspace(*pBegin))
|
||||
pBegin++;
|
||||
|
||||
// skip 0x
|
||||
if (!bStrict && psz[0] == '0' && tolower (psz[1]) == 'x')
|
||||
psz += 2;
|
||||
|
||||
const unsigned char* pEnd = reinterpret_cast<const unsigned char*> (psz);
|
||||
const unsigned char* pBegin = pEnd;
|
||||
if (!bStrict && pBegin[0] == '0' && tolower(pBegin[1]) == 'x')
|
||||
pBegin += 2;
|
||||
|
||||
// Find end.
|
||||
auto pEnd = pBegin;
|
||||
while (charUnHex(*pEnd) != -1)
|
||||
pEnd++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user