Skip to content

Commit

Permalink
keyfile: parse 0x-prefixed values as hex
Browse files Browse the repository at this point in the history
  • Loading branch information
elfmz committed Feb 18, 2021
1 parent 7011ad9 commit be944a9
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions utils/src/KeyFileHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ int KeyFileValues::GetInt(const char *name, int def) const
{
const auto &it = find(name);
if (it != end()) {
sscanf(it->second.c_str(), "%d", &def);
const char *sz = it->second.c_str();
if (sz[0] == '0' && sz[1] == 'x') {
sscanf(sz + 2, "%x", &def);
} else {
sscanf(sz, "%d", &def);
}
}

return def;
Expand All @@ -58,7 +63,12 @@ unsigned int KeyFileValues::GetUInt(const char *name, unsigned int def) const
{
const auto &it = find(name);
if (it != end()) {
sscanf(it->second.c_str(), "%u", &def);
const char *sz = it->second.c_str();
if (sz[0] == '0' && sz[1] == 'x') {
sscanf(sz + 2, "%x", &def);
} else {
sscanf(sz, "%u", &def);
}
}

return def;
Expand All @@ -68,7 +78,12 @@ unsigned long long KeyFileValues::GetULL(const char *name, unsigned long long de
{
const auto &it = find(name);
if (it != end()) {
sscanf(it->second.c_str(), "%llu", &def);
const char *sz = it->second.c_str();
if (sz[0] == '0' && sz[1] == 'x') {
sscanf(sz + 2, "%llx", &def);
} else {
sscanf(sz, "%llu", &def);
}
}

return def;
Expand Down

0 comments on commit be944a9

Please sign in to comment.