From 97a9a76ff9ca663e9b791e85c5258a06a377fcaf Mon Sep 17 00:00:00 2001 From: Vitaliy Urusovskij Date: Wed, 26 May 2021 02:04:06 +0300 Subject: [PATCH] Fix parsing of threads in stress/memory tests (#5695) * Fix parsing of threads in stress/memory tests * Replace `char*` with `string` due `char*` can't be modified --- tests/stress_tests/common/utils.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/stress_tests/common/utils.cpp b/tests/stress_tests/common/utils.cpp index d93513a1c6c..4baa8c0f1bb 100644 --- a/tests/stress_tests/common/utils.cpp +++ b/tests/stress_tests/common/utils.cpp @@ -24,14 +24,16 @@ std::string fileNameNoExt(const std::string &filepath) { } -static size_t parseLine(char* line) { - // This assumes that a digit will be found and the line ends in " Kb". - size_t i = strlen(line); - const char* p = line; - while (*p <'0' || *p > '9') p++; - line[i-3] = '\0'; - i = (size_t)atoi(p); - return i; +/// Parses number from provided string +static int parseLine(std::string line) { + std::string res = ""; + for (auto c: line) + if (isdigit(c)) + res += c; + if (res.empty()) + // If number wasn't found return -1 + return -1; + return std::stoi(res); } #ifdef _WIN32