Skip to content

Commit

Permalink
paramsd: Replace strtod by std::stringstream
Browse files Browse the repository at this point in the history
Using std::stringstream allows conversion of double to string
independent of the current locale setting.

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed May 2, 2019
1 parent e3860e4 commit d047fa1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/ccmain/paramsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@

#include "paramsd.h"
#include <cstdio> // for fclose, fopen, fprintf, sprintf, FILE
#include <cstdlib> // for atoi, strtod
#include <cstdlib> // for atoi
#include <cstring> // for strcmp, strcspn, strlen, strncpy
#include <locale> // for std::locale::classic
#include <map> // for map, _Rb_tree_iterator, map<>::iterator
#include <memory> // for unique_ptr
#include <sstream> // for std::stringstream
#include <utility> // for pair
#include "genericvector.h" // for GenericVector
#include "params.h" // for ParamsVectors, StringParam, BoolParam
Expand Down Expand Up @@ -158,7 +160,12 @@ void ParamContent::SetValue(const char* val) {
} else if (param_type_ == VT_BOOLEAN) {
bIt->set_value(atoi(val));
} else if (param_type_ == VT_DOUBLE) {
dIt->set_value(strtod(val, nullptr));
std::stringstream stream(val);
// Use "C" locale for reading double value.
stream.imbue(std::locale::classic());
double d = 0;
stream >> d;
dIt->set_value(d);
} else if (param_type_ == VT_STRING) {
sIt->set_value(val);
}
Expand Down

0 comments on commit d047fa1

Please sign in to comment.