Skip to content

Commit fa186eb

Browse files
author
MarcoFalke
committed
Remove strtol in torcontrol
1 parent fe03f7a commit fa186eb

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/torcontrol.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,17 @@
2222
#include <deque>
2323
#include <functional>
2424
#include <set>
25-
#include <stdlib.h>
2625
#include <vector>
2726

28-
#include <boost/signals2/signal.hpp>
29-
#include <boost/algorithm/string/split.hpp>
3027
#include <boost/algorithm/string/classification.hpp>
3128
#include <boost/algorithm/string/replace.hpp>
29+
#include <boost/algorithm/string/split.hpp>
3230

33-
#include <event2/bufferevent.h>
3431
#include <event2/buffer.h>
35-
#include <event2/util.h>
32+
#include <event2/bufferevent.h>
3633
#include <event2/event.h>
3734
#include <event2/thread.h>
35+
#include <event2/util.h>
3836

3937
/** Default control port */
4038
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)
277275
if (j == 3 && value[i] > '3') {
278276
j--;
279277
}
280-
escaped_value.push_back(strtol(value.substr(i, j).c_str(), nullptr, 8));
278+
const auto end{i + j};
279+
uint8_t val{0};
280+
while (i < end) {
281+
val *= 8;
282+
val += value[i++] - '0';
283+
}
284+
escaped_value.push_back(char(val));
281285
// Account for automatic incrementing at loop end
282-
i += j - 1;
286+
--i;
283287
} else {
284288
escaped_value.push_back(value[i]);
285289
}

test/lint/lint-locale-dependence.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,12 @@ export LC_ALL=C
3737
# See https://doc.qt.io/qt-5/qcoreapplication.html#locale-settings and
3838
# https://stackoverflow.com/a/34878283 for more details.
3939

40-
# TODO: Reduce KNOWN_VIOLATIONS by replacing uses of locale dependent stoul/strtol with locale
41-
# independent ToIntegral<T>(...) or the ParseInt*() functions.
4240
# TODO: Reduce KNOWN_VIOLATIONS by replacing uses of locale dependent snprintf with strprintf.
4341
KNOWN_VIOLATIONS=(
4442
"src/dbwrapper.cpp:.*vsnprintf"
4543
"src/test/dbwrapper_tests.cpp:.*snprintf"
4644
"src/test/fuzz/locale.cpp"
4745
"src/test/fuzz/string.cpp"
48-
"src/torcontrol.cpp:.*strtol"
4946
)
5047

5148
REGEXP_IGNORE_EXTERNAL_DEPENDENCIES="^src/(crypto/ctaes/|leveldb/|secp256k1/|minisketch/|tinyformat.h|univalue/)"

0 commit comments

Comments
 (0)