Skip to content

Commit

Permalink
Merge pull request #785 from lioncash/string
Browse files Browse the repository at this point in the history
Common: Fix AsciiToHex returning true on overflow values
  • Loading branch information
shuffle2 committed Aug 12, 2014
2 parents 9f4008c + 5afb9cc commit 4301081
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Source/Core/Common/StringUtil.cpp
Expand Up @@ -28,12 +28,18 @@
// faster than sscanf
bool AsciiToHex(const std::string& _szValue, u32& result)
{
// Set errno to a good state.
errno = 0;

char *endptr = nullptr;
const u32 value = strtoul(_szValue.c_str(), &endptr, 16);

if (!endptr || *endptr)
return false;

if (errno == ERANGE)
return false;

result = value;
return true;
}
Expand Down

0 comments on commit 4301081

Please sign in to comment.