From e412e1b41ce7d0ac51c4ddd5d303ca11791f6b00 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Sat, 29 Dec 2018 15:18:26 +0300 Subject: [PATCH] Revert to lexical_cast, catch out-of-range exceptions --- components/fallback/fallback.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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;