X-CASH-official / xcash-core

📦 First Cryptonote coin with public & private transactions, custom DPOS consensus
https://xcash.foundation
Other
66 stars 20 forks source link

Fix uninitialized variable find from valgrind #33

Closed ghost closed 2 years ago

ghost commented 2 years ago

Description

Valgrind got cranky and claimed the daemon was using uninitialized variables.

Well, actually it said this:

==1102442== Conditional jump or move depends on uninitialised value(s)
==1102442==    at 0x508CAA8: int* std::__find_if<int*, __gnu_cxx::__ops::_Iter_pred<get_network_block_database_hash(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, unsigned long)::{lambda(int)#1}> >(__gnu_cxx::__ops::_Iter_pred<get_network_block_database_hash(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, unsigned long)::{lambda(int)#1}>, __gnu_cxx::__ops::_Iter_pred<get_network_block_database_hash(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, unsigned long)::{lambda(int)#1}>, __gnu_cxx::__ops::_Iter_pred<get_network_block_database_hash(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, unsigned long)::{lambda(int)#1}>, std::random_access_iterator_tag) (stl_algo.h:148)
==1102442==    by 0x509AF73: __find_if<int*, __gnu_cxx::__ops::_Iter_pred<get_network_block_database_hash(std::vector<std::__cxx11::basic_string<char> >&, std::vector<std::__cxx11::basic_string<char> >&, std::size_t)::<lambda(int)> > > (stl_algo.h:161)
==1102442==    by 0x509AF73: find_if<int*, get_network_block_database_hash(std::vector<std::__cxx11::basic_string<char> >&, std::vector<std::__cxx11::basic_string<char> >&, std::size_t)::<lambda(int)> > (stl_algo.h:3969)
==1102442==    by 0x509AF73: none_of<int*, get_network_block_database_hash(std::vector<std::__cxx11::basic_string<char> >&, std::vector<std::__cxx11::basic_string<char> >&, std::size_t)::<lambda(int)> > (stl_algo.h:526)
==1102442==    by 0x509AF73: any_of<int*, get_network_block_database_hash(std::vector<std::__cxx11::basic_string<char> >&, std::vector<std::__cxx11::basic_string<char> >&, std::size_t)::<lambda(int)> > (stl_algo.h:544)
==1102442==    by 0x509AF73: get_network_block_database_hash(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, unsigned long) (blockchain.cpp:4100)
==1102442==    by 0x50C405B: check_block_verifier_node_signed_block(cryptonote::block, unsigned long) (blockchain.cpp:4270)
==1102442==    by 0x50C4A27: cryptonote::Blockchain::add_new_block(cryptonote::block const&, cryptonote::block_verification_context&) (blockchain.cpp:4323)
==1102442==    by 0x50F8FD9: cryptonote::core::add_new_block(cryptonote::block const&, cryptonote::block_verification_context&) (cryptonote_core.cpp:1333)
==1102442==    by 0x5109B70: cryptonote::core::handle_incoming_block(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cryptonote::block_verification_context&, bool) (cryptonote_core.cpp:1380)
==1102442==    by 0x4E560D8: cryptonote::t_cryptonote_protocol_handler<cryptonote::core>::try_add_next_blocks(cryptonote::cryptonote_connection_context&) (cryptonote_protocol_handler.inl:1192)
==1102442==    by 0x4E5A169: cryptonote::t_cryptonote_protocol_handler<cryptonote::core>::handle_response_get_objects(int, cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request&, cryptonote::cryptonote_connection_context&) (cryptonote_protocol_handler.inl:1057)
==1102442==    by 0x2BF34F: operator() (mem_fn_template.hpp:393)
==1102442==    by 0x2BF34F: operator()<int, boost::_mfi::mf3<int, cryptonote::t_cryptonote_protocol_handler<cryptonote::core>, int, cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request&, cryptonote::cryptonote_connection_context&>, boost::_bi::rrlist3<int&, boost::value_initialized<cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request>&, cryptonote::cryptonote_connection_context&> > (bind.hpp:453)
==1102442==    by 0x2BF34F: operator()<int&, boost::value_initialized<cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request>&, cryptonote::cryptonote_connection_context&> (bind.hpp:1330)
==1102442==    by 0x2BF34F: int epee::net_utils::buff_to_t_adapter<cryptonote::t_cryptonote_protocol_handler<cryptonote::core>, cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request, cryptonote::cryptonote_connection_context, boost::_bi::bind_t<int, boost::_mfi::mf3<int, cryptonote::t_cryptonote_protocol_handler<cryptonote::core>, int, cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request&, cryptonote::cryptonote_connection_context&>, boost::_bi::list4<boost::_bi::value<cryptonote::t_cryptonote_protocol_handler<cryptonote::core>*>, boost::arg<1>, boost::arg<2>, boost::arg<3> > > >(cryptonote::t_cryptonote_protocol_handler<cryptonote::core>*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::_bi::bind_t<int, boost::_mfi::mf3<int, cryptonote::t_cryptonote_protocol_handler<cryptonote::core>, int, cryptonote::NOTIFY_RESPONSE_GET_OBJECTS::request&, cryptonote::cryptonote_connection_context&>, boost::_bi::list4<boost::_bi::value<cryptonote::t_cryptonote_protocol_handler<cryptonote::core>*>, boost::arg<1>, boost::arg<2>, boost::arg<3> > >, cryptonote::cryptonote_connection_context&) (levin_abstract_invoke2.h:216)

<<< etc... etc... etc... ad nauseam...>>>

==1102442==    by 0x211D3B: complete (scheduler_operation.hpp:40)
==1102442==    by 0x211D3B: do_run_one (scheduler.ipp:447)
==1102442==    by 0x211D3B: boost::asio::detail::scheduler::run(boost::system::error_code&) (scheduler.ipp:200)
==1102442==    by 0x4E12E74: run (io_context.ipp:63)
==1102442==    by 0x4E12E74: epee::net_utils::boosted_tcp_server<epee::levin::async_protocol_handler<nodetool::p2p_connection_context_t<cryptonote::cryptonote_connection_context> > >::worker_thread() (abstract_tcp_server2.inl:902)
==1102442==    by 0x4DF9FFC: operator() (mem_fn_template.hpp:49)
==1102442==    by 0x4DF9FFC: operator()<bool, boost::_mfi::mf0<bool, epee::net_utils::boosted_tcp_server<epee::levin::async_protocol_handler<nodetool::p2p_connection_context_t<cryptonote::cryptonote_connection_context> > > >, boost::_bi::list0> (bind.hpp:249)
==1102442==    by 0x4DF9FFC: operator() (bind.hpp:1294)
==1102442==    by 0x4DF9FFC: boost::detail::thread_data<boost::_bi::bind_t<bool, boost::_mfi::mf0<bool, epee::net_utils::boosted_tcp_server<epee::levin::async_protocol_handler<nodetool::p2p_connection_context_t<cryptonote::cryptonote_connection_context> > > >, boost::_bi::list1<boost::_bi::value<epee::net_utils::boosted_tcp_server<epee::levin::async_protocol_handler<nodetool::p2p_connection_context_t<cryptonote::cryptonote_connection_context> > >*> > > >::run() (thread.hpp:120)
==1102442==    by 0x590B43A: ??? (in /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.71.0)
==1102442==    by 0x5DA3608: start_thread (pthread_create.c:477)
==1102442==    by 0x5EDD162: clone (clone.S:95)
==1102442==  Uninitialised value was created by a stack allocation
==1102442==    at 0x509A6FA: get_network_block_database_hash(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, unsigned long) (blockchain.cpp:4047)

Type of change

I initialized three int variables. Oh, and I added some spaces to put a brace in the correct column. :)

How Has This Been Tested?

I've been running the change on the testnet for the past day.

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information