From a8c22cc4d1e3c55d2b2f16a72fe4130be54baaa4 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sat, 18 Jul 2015 08:16:21 +0200 Subject: [PATCH] util: use locale-independent parsing in ParseDouble Use locale-indepent C++ based parsing instead of C's strtod, which checks for different input based on the user's locale. Fixes #6443. --- src/utilstrencodings.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index 14482c996..142d5a4eb 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -480,11 +480,12 @@ bool ParseDouble(const std::string& str, double *out) return false; if (str.size() >= 2 && str[0] == '0' && str[1] == 'x') // No hexadecimal floats allowed return false; - char *endp = NULL; - errno = 0; // strtod will not set errno if valid - double n = strtod(str.c_str(), &endp); - if(out) *out = n; - return endp && *endp == 0 && !errno; + std::istringstream text(str); + text.imbue(std::locale::classic()); + double result; + text >> result; + if(out) *out = result; + return text.eof() && !text.fail(); } std::string FormatParagraph(const std::string in, size_t width, size_t indent)