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>
This commit is contained in:
Ethan Nicholas 2017-01-03 13:08:34 -05:00 committed by Skia Commit-Bot
parent 613a697ed1
commit e337b18560

View File

@ -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) {