-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Remove strtol in torcontrol #23538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove strtol in torcontrol #23538
Conversation
|
Concept ACK.
|
torcontrol.cpp:279:49: runtime error: implicit conversion from type 'unsigned char' of value 255 (8-bit, unsigned) to type 'char' changed the value to -1 (8-bit, signed)
#0 0x557c2b741c35 in ParseTorReplyMapping(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) src/torcontrol.cpp:279:49
#1 0x557c2ad31efb in torcontrol_tests::CheckParseTorReplyMapping(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >) src/test/torcontrol_tests.cpp:61:16
#2 0x557c2ad2efd8 in torcontrol_tests::util_ParseTorReplyMapping::test_method() src/test/torcontrol_tests.cpp:150:5
#3 0x557c2ad2ceea in torcontrol_tests::util_ParseTorReplyMapping_invoker() src/test/torcontrol_tests.cpp:73:1
#4 0x557c2a46a89f in boost::detail::function::void_function_invoker0<void (*)(), void>::invoke(boost::detail::function::function_buffer&) /usr/include/boost/function/function_template.hpp:117:11
#5 0x7fad31b494c1 (/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.74.0+0x274c1)
#6 0x7fad31b4f410 in boost::execution_monitor::catch_signals(boost::function<int ()> const&) (/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.74.0+0x2d410)
#7 0x7fad31b4f900 in boost::execution_monitor::execute(boost::function<int ()> const&) (/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.74.0+0x2d900)
#8 0x7fad31b4f9bb in boost::execution_monitor::vexecute(boost::function<void ()> const&) (/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.74.0+0x2d9bb)
#9 0x7fad31b73876 in boost::unit_test::unit_test_monitor_t::execute_and_translate(boost::function<void ()> const&, unsigned long) (/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.74.0+0x51876)
#10 0x7fad31b925a6 (/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.74.0+0x705a6)
#11 0x7fad31b92bf3 (/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.74.0+0x70bf3)
#12 0x7fad31b92bf3 (/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.74.0+0x70bf3)
#13 0x7fad31b5a79a in boost::unit_test::framework::run(unsigned long, bool) (/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.74.0+0x3879a)
#14 0x7fad31b6c6f9 in boost::unit_test::unit_test_main(bool (*)(), int, char**) (/lib/x86_64-linux-gnu/libboost_unit_test_framework.so.1.74.0+0x4a6f9)
#15 0x557c2a39d83d in main /usr/include/boost/test/unit_test.hpp:64:12
#16 0x7fad311bffcf (/lib/x86_64-linux-gnu/libc.so.6+0x2dfcf)
#17 0x7fad311c007c in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2e07c)
#18 0x557c2a2ec974 in _start (/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-x86_64-pc-linux-gnu/src/test/test_bitcoin+0x10d3974)
SUMMARY: UndefinedBehaviorSanitizer: implicit-integer-sign-change torcontrol.cpp:279:49 in
make[3]: *** [Makefile:19175: test/torcontrol_tests.cpp.test] Error 1 |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
Concept ACK. |
|
honestly, I kind of wonder why this isn't implemented with a little kind of loop. |
fa1d030 to
fa9fe9f
Compare
The validation pass needs to be a different loop than the calculation loop, so I think a one-line function call is fine. If speed is a concern, ToIntegral could be changed to use Though, changed to a |
fa9fe9f to
fa186eb
Compare
|
Code review and tested ACK fa186eb
I don't think speed is a concern, the whole construction just looked fragile and bolted on to me, I think it's much clearer what the code does and what the intent is this way. |
|
It looks like this code is sufficiently tested in I've done some manual testing, too, in this way: |
The sequence of octal chars is fully validated before calling
strtol, so it can be replaced by a simple loop. This removes the last "locale depended"strtolcall. Also, removes some unused includes.