Skip to content

Commit d047fa1

Browse files
committed
paramsd: Replace strtod by std::stringstream
Using std::stringstream allows conversion of double to string independent of the current locale setting. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent e3860e4 commit d047fa1

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/ccmain/paramsd.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828

2929
#include "paramsd.h"
3030
#include <cstdio> // for fclose, fopen, fprintf, sprintf, FILE
31-
#include <cstdlib> // for atoi, strtod
31+
#include <cstdlib> // for atoi
3232
#include <cstring> // for strcmp, strcspn, strlen, strncpy
33+
#include <locale> // for std::locale::classic
3334
#include <map> // for map, _Rb_tree_iterator, map<>::iterator
3435
#include <memory> // for unique_ptr
36+
#include <sstream> // for std::stringstream
3537
#include <utility> // for pair
3638
#include "genericvector.h" // for GenericVector
3739
#include "params.h" // for ParamsVectors, StringParam, BoolParam
@@ -158,7 +160,12 @@ void ParamContent::SetValue(const char* val) {
158160
} else if (param_type_ == VT_BOOLEAN) {
159161
bIt->set_value(atoi(val));
160162
} else if (param_type_ == VT_DOUBLE) {
161-
dIt->set_value(strtod(val, nullptr));
163+
std::stringstream stream(val);
164+
// Use "C" locale for reading double value.
165+
stream.imbue(std::locale::classic());
166+
double d = 0;
167+
stream >> d;
168+
dIt->set_value(d);
162169
} else if (param_type_ == VT_STRING) {
163170
sIt->set_value(val);
164171
}

0 commit comments

Comments
 (0)