Common: Fix AsciiToHex returning true on overflow values
We should be checking errno against ERANGE.
This commit is contained in:
parent
36af1b518d
commit
5afb9cc5c4
|
@ -28,12 +28,18 @@
|
||||||
// faster than sscanf
|
// faster than sscanf
|
||||||
bool AsciiToHex(const std::string& _szValue, u32& result)
|
bool AsciiToHex(const std::string& _szValue, u32& result)
|
||||||
{
|
{
|
||||||
|
// Set errno to a good state.
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
char *endptr = nullptr;
|
char *endptr = nullptr;
|
||||||
const u32 value = strtoul(_szValue.c_str(), &endptr, 16);
|
const u32 value = strtoul(_szValue.c_str(), &endptr, 16);
|
||||||
|
|
||||||
if (!endptr || *endptr)
|
if (!endptr || *endptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (errno == ERANGE)
|
||||||
|
return false;
|
||||||
|
|
||||||
result = value;
|
result = value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue