diff --git a/components/fallback/fallback.cpp b/components/fallback/fallback.cpp index 70ee2f681..473d10ba4 100644 --- a/components/fallback/fallback.cpp +++ b/components/fallback/fallback.cpp @@ -2,6 +2,8 @@ #include +#include + namespace Fallback { Map::Map(const std::map& fallback):mFallbackMap(fallback) @@ -24,9 +26,11 @@ namespace Fallback { try { - return std::stof(fallback); + // We have to rely on Boost because std::stof from C++11 + // uses the current locale for separators which we don't want and often silently ignores parsing errors. + return boost::lexical_cast(fallback); } - catch (const std::invalid_argument&) + catch (boost::bad_lexical_cast&) { Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback"; } @@ -48,6 +52,10 @@ namespace Fallback { Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is not a valid number, using 0 as a fallback"; } + catch (const std::out_of_range&) + { + Log(Debug::Error) << "Error: '" << fall << "' setting value (" << fallback << ") is out of range, using 0 as a fallback"; + } } return 0;