diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-11-17 20:37:16 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-11-18 18:13:21 +0100 |
commit | fa186eb7f45a9d420503f96ff3a5f753afb75dec (patch) | |
tree | 133ac5125895df40b7c6a3f8d7246f9df0ba54e0 | |
parent | fe03f7a37fd0ef05149161f6b95a25493e1fe38f (diff) |
Remove strtol in torcontrol
-rw-r--r-- | src/torcontrol.cpp | 18 | ||||
-rwxr-xr-x | test/lint/lint-locale-dependence.sh | 3 |
2 files changed, 11 insertions, 10 deletions
diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index 55618a5c57..776981b7f7 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -22,19 +22,17 @@ #include <deque> #include <functional> #include <set> -#include <stdlib.h> #include <vector> -#include <boost/signals2/signal.hpp> -#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/replace.hpp> +#include <boost/algorithm/string/split.hpp> -#include <event2/bufferevent.h> #include <event2/buffer.h> -#include <event2/util.h> +#include <event2/bufferevent.h> #include <event2/event.h> #include <event2/thread.h> +#include <event2/util.h> /** Default control port */ const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:9051"; @@ -277,9 +275,15 @@ std::map<std::string,std::string> 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 b58600e6cb..661bc35175 100755 --- a/test/lint/lint-locale-dependence.sh +++ b/test/lint/lint-locale-dependence.sh @@ -37,15 +37,12 @@ export LC_ALL=C # See https://doc.qt.io/qt-5/qcoreapplication.html#locale-settings and # https://stackoverflow.com/a/34878283 for more details. -# TODO: Reduce KNOWN_VIOLATIONS by replacing uses of locale dependent stoul/strtol with locale -# independent ToIntegral<T>(...) or the ParseInt*() functions. # TODO: Reduce KNOWN_VIOLATIONS by replacing uses of locale dependent snprintf with strprintf. KNOWN_VIOLATIONS=( "src/dbwrapper.cpp:.*vsnprintf" "src/test/dbwrapper_tests.cpp:.*snprintf" "src/test/fuzz/locale.cpp" "src/test/fuzz/string.cpp" - "src/torcontrol.cpp:.*strtol" ) REGEXP_IGNORE_EXTERNAL_DEPENDENCIES="^src/(crypto/ctaes/|leveldb/|secp256k1/|minisketch/|tinyformat.h|univalue/)" |