diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-01-03 13:08:34 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-03 18:58:45 +0000 |
commit | e337b185602ff198ef8b4567db3f6ef01f89475e (patch) | |
tree | ebd191d88a74a5fbbecff84bad20a56c67ea84b5 /src/sksl | |
parent | 613a697ed124296620b2280533fad2eef776ba54 (diff) |
Force classic locale when parsing floats in skslc.
atof is locale dependent, which can lead to bugs when a decimal separator is something other than a dot.
BUG=skia:
Change-Id: I6f161d686ddea86ce9968e46b632bc79a99ef656
Reviewed-on: https://skia-review.googlesource.com/6532
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl')
-rw-r--r-- | src/sksl/SkSLUtil.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/sksl/SkSLUtil.cpp b/src/sksl/SkSLUtil.cpp index 98e5fa4599..e93a953990 100644 --- a/src/sksl/SkSLUtil.cpp +++ b/src/sksl/SkSLUtil.cpp @@ -11,6 +11,9 @@ #define __STDC_FORMAT_MACROS #endif #include <cinttypes> +#include <locale> +#include <sstream> +#include <string> namespace SkSL { @@ -60,7 +63,12 @@ int stoi(SkString s) { } double stod(SkString s) { - return atof(s.c_str()); + double result; + std::string str(s.c_str(), s.size()); + std::stringstream buffer(str); + buffer.imbue(std::locale::classic()); + buffer >> result; + return result; } long stol(SkString s) { |