From 1f4e8a0cf9305e2de776a89090599fcbbb0866c8 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Tue, 1 Oct 2024 04:05:07 +0000 Subject: [PATCH] merge bitcoin#23538: Remove strtol in torcontrol --- src/torcontrol.cpp | 17 ++++++++++------- test/lint/lint-locale-dependence.sh | 1 - 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index 2c01b562f3..21ab55195a 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -21,16 +21,13 @@ #include #include #include -#include #include -#include - -#include #include -#include +#include #include #include +#include /** Default control port */ const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:9051"; @@ -273,9 +270,15 @@ std::map ParseTorReplyMapping(const std::string &s) if (j == 3 && value[i] > '3') { j--; } - escaped_value.push_back(strtol(value.substr(i, j).c_str(), nullptr, 8)); + const auto end{i + j}; + uint8_t val{0}; + while (i < end) { + val *= 8; + val += value[i++] - '0'; + } + escaped_value.push_back(char(val)); // Account for automatic incrementing at loop end - i += j - 1; + --i; } else { escaped_value.push_back(value[i]); } diff --git a/test/lint/lint-locale-dependence.sh b/test/lint/lint-locale-dependence.sh index 2531d0b501..18f0a793f0 100755 --- a/test/lint/lint-locale-dependence.sh +++ b/test/lint/lint-locale-dependence.sh @@ -47,7 +47,6 @@ KNOWN_VIOLATIONS=( "src/test/dbwrapper_tests.cpp:.*snprintf" "src/test/fuzz/locale.cpp" "src/test/fuzz/string.cpp" - "src/torcontrol.cpp:.*strtol" "src/util/strencodings.cpp:.*strtoll" "src/util/system.cpp:.*fprintf" )