Skip to content

Commit 5d92fbf

Browse files
committed
Replace sscanf by std::istringstream
Using std::istringstream allows conversion of string to float independent of the current locale setting. Signed-off-by: Stefan Weil <[email protected]>
1 parent c76ceaf commit 5d92fbf

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/classify/clusttool.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,22 @@ uint16_t ReadSampleSize(TFile *fp) {
142142
*/
143143
PARAM_DESC *ReadParamDesc(TFile *fp, uint16_t N) {
144144
PARAM_DESC *ParamDesc;
145-
char linear_token[TOKENSIZE], essential_token[TOKENSIZE];
146145

147146
ParamDesc = static_cast<PARAM_DESC *>(Emalloc (N * sizeof (PARAM_DESC)));
148147
for (int i = 0; i < N; i++) {
149148
const int kMaxLineSize = TOKENSIZE * 4;
150149
char line[kMaxLineSize];
151150
ASSERT_HOST(fp->FGets(line, kMaxLineSize) != nullptr);
152-
ASSERT_HOST(sscanf(line,
153-
"%" QUOTED_TOKENSIZE "s %" QUOTED_TOKENSIZE "s %f %f",
154-
linear_token, essential_token, &ParamDesc[i].Min,
155-
&ParamDesc[i].Max) == 4);
151+
std::istringstream stream(line);
152+
// Use "C" locale (needed for float values Min, Max).
153+
stream.imbue(std::locale::classic());
154+
std::string linear_token;
155+
stream >> linear_token;
156+
std::string essential_token;
157+
stream >> essential_token;
158+
stream >> ParamDesc[i].Min;
159+
stream >> ParamDesc[i].Max;
160+
ASSERT_HOST(!stream.fail());
156161
ParamDesc[i].Circular = (linear_token[0] == 'c');
157162
ParamDesc[i].NonEssential = (essential_token[0] != 'e');
158163
ParamDesc[i].Range = ParamDesc[i].Max - ParamDesc[i].Min;

0 commit comments

Comments
 (0)