From 5d92fbf010667d97cb522873d18d63025e35a4a4 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sun, 12 May 2019 14:59:35 +0200 Subject: [PATCH] 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 --- src/classify/clusttool.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/classify/clusttool.cpp b/src/classify/clusttool.cpp index 3ff32f003d..2f2fd1f70b 100644 --- a/src/classify/clusttool.cpp +++ b/src/classify/clusttool.cpp @@ -142,17 +142,22 @@ uint16_t ReadSampleSize(TFile *fp) { */ PARAM_DESC *ReadParamDesc(TFile *fp, uint16_t N) { PARAM_DESC *ParamDesc; - char linear_token[TOKENSIZE], essential_token[TOKENSIZE]; ParamDesc = static_cast(Emalloc (N * sizeof (PARAM_DESC))); for (int i = 0; i < N; i++) { const int kMaxLineSize = TOKENSIZE * 4; char line[kMaxLineSize]; ASSERT_HOST(fp->FGets(line, kMaxLineSize) != nullptr); - ASSERT_HOST(sscanf(line, - "%" QUOTED_TOKENSIZE "s %" QUOTED_TOKENSIZE "s %f %f", - linear_token, essential_token, &ParamDesc[i].Min, - &ParamDesc[i].Max) == 4); + std::istringstream stream(line); + // Use "C" locale (needed for float values Min, Max). + stream.imbue(std::locale::classic()); + std::string linear_token; + stream >> linear_token; + std::string essential_token; + stream >> essential_token; + stream >> ParamDesc[i].Min; + stream >> ParamDesc[i].Max; + ASSERT_HOST(!stream.fail()); ParamDesc[i].Circular = (linear_token[0] == 'c'); ParamDesc[i].NonEssential = (essential_token[0] != 'e'); ParamDesc[i].Range = ParamDesc[i].Max - ParamDesc[i].Min;