Skip to content

Commit 6d26e81

Browse files
committed
use fast_float instead of std::stod, because std::stod uses locale to parse the value which might be wrong.
1 parent f031db6 commit 6d26e81

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ option(ENABLE_TESTS "Enable Unittests" ON)
99
set(CMAKE_CXX_STANDARD 11)
1010
set(CMAKE_CXX_STANDARD_REQUIRED True)
1111

12+
find_package(FastFloat REQUIRED)
13+
1214
set(GCC_COMPILE_FLAGS "-Wextra -Wall -Wfloat-equal -Wundef -Wshadow \
1315
-Wpointer-arith -Wcast-align -Wstrict-prototypes -Wwrite-strings \
1416
-Waggregate-return -Wcast-qual -Wswitch-default -Wswitch-enum -Wconversion \

src/dbc.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <libdbc/exceptions/error.hpp>
22
#include <libdbc/utils/utils.hpp>
33
#include <libdbc/dbc.hpp>
4+
#include <fast_float/fast_float.h>
45

56
#include <regex>
67

@@ -166,10 +167,14 @@ namespace libdbc {
166167
bool is_bigendian = (std::stoul(match.str(5)) == 0);
167168
bool is_signed = (match.str(6) == "-");
168169
// Alternate groups because a group is for the decimal portion
169-
double factor = std::stod(match.str(7));
170-
double offset = std::stod(match.str(9));
171-
double min = std::stod(match.str(11));
172-
double max = std::stod(match.str(13));
170+
double factor;
171+
fast_float::from_chars(match.str(7).data(), match.str(7).data() + match.str(7).size(), factor);
172+
double offset;
173+
fast_float::from_chars(match.str(9).data(), match.str(9).data() + match.str(9).size(), offset);
174+
double min;
175+
fast_float::from_chars(match.str(11).data(), match.str(11).data() + match.str(11).size(), min);
176+
double max;
177+
fast_float::from_chars(match.str(13).data(), match.str(13).data() + match.str(13).size(), max);
173178
std::string unit = match.str(15);
174179

175180
std::vector<std::string> receivers;

0 commit comments

Comments
 (0)