diff options
author | Wouter van Oortmerssen <aardappel@gmail.com> | 2020-01-09 11:47:02 -0800 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2020-01-09 11:48:09 -0800 |
commit | 55686100aa6f8b4867e8de62768d8fc0ecc5a541 (patch) | |
tree | e6308ea6cc02a0457a7b020424b0f4490531e721 /src | |
parent | 718351831dbb1c047d8f93e5181c3c083ca0b5d2 (diff) | |
download | flatbuffers-55686100aa6f8b4867e8de62768d8fc0ecc5a541.tar.gz flatbuffers-55686100aa6f8b4867e8de62768d8fc0ecc5a541.tar.bz2 flatbuffers-55686100aa6f8b4867e8de62768d8fc0ecc5a541.zip |
Changed direct calls to strtod to use StringToNumber
StringToNumber will correctly use locale-insensitive functions
when available.
Change-Id: I6bde11039a541634186f8f791012af2eb0d86b8d
Diffstat (limited to 'src')
-rw-r--r-- | src/idl_parser.cpp | 12 | ||||
-rw-r--r-- | src/reflection.cpp | 15 |
2 files changed, 20 insertions, 7 deletions
diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index e082352b..7c3c46dc 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -2764,10 +2764,13 @@ CheckedError Parser::ParseFlexBufferValue(flexbuffers::Builder *builder) { builder->Int(StringToInt(attribute_.c_str())); EXPECT(kTokenIntegerConstant); break; - case kTokenFloatConstant: - builder->Double(strtod(attribute_.c_str(), nullptr)); + case kTokenFloatConstant: { + double d; + StringToNumber(attribute_.c_str(), &d); + builder->Double(d); EXPECT(kTokenFloatConstant); break; + } default: if (IsIdent("true")) { builder->Bool(true); @@ -3220,13 +3223,14 @@ Offset<reflection::Field> FieldDef::Serialize(FlatBufferBuilder *builder, auto docs__ = parser.opts.binary_schema_comments ? builder->CreateVectorOfStrings(doc_comment) : 0; + double d; + StringToNumber(value.constant.c_str(), &d); return reflection::CreateField( *builder, name__, type__, id, value.offset, // Is uint64>max(int64) tested? IsInteger(value.type.base_type) ? StringToInt(value.constant.c_str()) : 0, // result may be platform-dependent if underlying is float (not double) - IsFloat(value.type.base_type) ? strtod(value.constant.c_str(), nullptr) - : 0.0, + IsFloat(value.type.base_type) ? d : 0.0, deprecated, required, key, attr__, docs__); // TODO: value.constant is almost always "0", we could save quite a bit of // space by sharing it. Same for common values of value.type. diff --git a/src/reflection.cpp b/src/reflection.cpp index 409dbd03..77ea0dcf 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -56,7 +56,13 @@ double GetAnyValueF(reflection::BaseType type, const uint8_t *data) { case reflection::String: { auto s = reinterpret_cast<const String *>(ReadScalar<uoffset_t>(data) + data); - return s ? strtod(s->c_str(), nullptr) : 0.0; + if (s) { + double d; + StringToNumber(s->c_str(), &d); + return d; + } else { + return 0.0; + } } default: return static_cast<double>(GetAnyValueI(type, data)); } @@ -149,9 +155,12 @@ void SetAnyValueF(reflection::BaseType type, uint8_t *data, double val) { void SetAnyValueS(reflection::BaseType type, uint8_t *data, const char *val) { switch (type) { case reflection::Float: - case reflection::Double: - SetAnyValueF(type, data, strtod(val, nullptr)); + case reflection::Double: { + double d; + StringToNumber(val, &d); + SetAnyValueF(type, data, d); break; + } // TODO: support strings. default: SetAnyValueI(type, data, StringToInt(val)); break; } |