Skip to content

Commit

Permalink
Merge pull request #6074 from delroth/netplay-fix
Browse files Browse the repository at this point in the history
Fix NetPlay settings reset issue
  • Loading branch information
delroth committed Sep 18, 2017
2 parents c50848b + 43f067c commit 1566f3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
24 changes: 13 additions & 11 deletions Source/Core/Common/StringUtil.cpp
Expand Up @@ -226,25 +226,27 @@ std::string StripQuotes(const std::string& s)
return s;
}

bool TryParse(const std::string& str, u32* const output)
bool TryParse(const std::string& str, u16* const output)
{
char* endptr = nullptr;

// Reset errno to a value other than ERANGE
errno = 0;

unsigned long value = strtoul(str.c_str(), &endptr, 0);
u64 value;
if (!TryParse(str, &value))
return false;

if (!endptr || *endptr)
if (value >= 0x10000ull && value <= 0xFFFFFFFFFFFF0000ull)
return false;

if (errno == ERANGE)
*output = static_cast<u16>(value);
return true;
}

bool TryParse(const std::string& str, u32* const output)
{
u64 value;
if (!TryParse(str, &value))
return false;

#if ULONG_MAX > UINT_MAX
if (value >= 0x100000000ull && value <= 0xFFFFFFFF00000000ull)
return false;
#endif

*output = static_cast<u32>(value);
return true;
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Common/StringUtil.h
Expand Up @@ -59,6 +59,7 @@ std::string ThousandSeparate(I value, int spaces = 0)
std::string StringFromBool(bool value);

bool TryParse(const std::string& str, bool* output);
bool TryParse(const std::string& str, u16* output);
bool TryParse(const std::string& str, u32* output);
bool TryParse(const std::string& str, u64* output);

Expand Down

0 comments on commit 1566f3a

Please sign in to comment.