mirror of https://github.com/stella-emu/stella.git
catch exception in BSPF::stoi (fixes #958)
This commit is contained in:
parent
7676e9b4c8
commit
93ea39d615
|
@ -197,11 +197,14 @@ namespace BSPF
|
||||||
template<int BASE = 10>
|
template<int BASE = 10>
|
||||||
inline int stoi(string_view s, const int defaultValue = 0)
|
inline int stoi(string_view s, const int defaultValue = 0)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
int i{};
|
int i{};
|
||||||
s = s.substr(s.find_first_not_of(" "));
|
s = s.substr(s.find_first_not_of(" "));
|
||||||
auto result = std::from_chars(s.data(), s.data() + s.size(), i, BASE);
|
auto result = std::from_chars(s.data(), s.data() + s.size(), i, BASE);
|
||||||
return result.ec == std::errc() ? i : defaultValue;
|
return result.ec == std::errc() ? i : defaultValue;
|
||||||
}
|
}
|
||||||
|
catch(...) { return defaultValue; }
|
||||||
|
}
|
||||||
|
|
||||||
// Compare two strings (case insensitive)
|
// Compare two strings (case insensitive)
|
||||||
// Return negative, zero, positive result for <,==,> respectively
|
// Return negative, zero, positive result for <,==,> respectively
|
||||||
|
|
Loading…
Reference in New Issue