我一直在運行的valgrind通過我的應用程序由於其他各種問題,我不斷看到有關的警告:Valgrind的抱怨條件跳轉或移動依賴於未初始化的值(一個或多個)
==26447== Conditional jump or move depends on uninitialised value(s)
==26447== at 0x5C244F: int std::__int_to_char<char, unsigned long>(char*, unsigned long, char const*, std::_Ios_Fmtflags, bool) (in /home/alex/projects/Icarus/trunk/build/icarus)
==26447== by 0x5C2BB3: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<unsigned long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, unsigned long) const (in /home/alex/projects/Icarus/trunk/build/icarus)
==26447== by 0x5C2E1C: std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, unsigned long) const (in /home/alex/projects/Icarus/trunk/build/icarus)
==26447== by 0x5DB0BD: std::ostream& std::ostream::_M_insert<unsigned long>(unsigned long) (in /home/alex/projects/Icarus/trunk/build/icarus)
==26447== by 0x55C9B8: ExampleProcessor::Process(std::shared_ptr<Example>) (ExampleProcessor.hpp:49)
==26447== by 0x55D139: Controller::FIFO(std::shared_ptr<Message>) (Controller.hpp:51)
==26447== by 0x55D7C2: TCPConnection::respond(std::string) (TCPConnection.hpp:71)
==26447== by 0x55DC5E: TCPConnection::handle_read(boost::system::error_code const&, unsigned long) (TCPConnection.hpp:144)
==26447== by 0x595CD8: void boost::_mfi::mf2<void, TCPConnection, boost::system::error_code const&, unsigned long>::call<boost::shared_ptr<TCPConnection>, boost::system::error_code const, unsigned long>(boost::shared_ptr<TCPConnection>&, void const*, boost::system::error_code const&, unsigned long&) const (mem_fn_template.hpp:271)
==26447== by 0x591412: void boost::_mfi::mf2<void, TCPConnection, boost::system::error_code const&, unsigned long>::operator()<boost::shared_ptr<TCPConnection> >(boost::shared_ptr<TCPConnection>&, boost::system::error_code const&, unsigned long) const (mem_fn_template.hpp:286)
==26447== by 0x58A46D: void boost::_bi::list3<boost::_bi::value<boost::shared_ptr<TCPConnection> >, boost::arg<1> (*)(), boost::arg<2> (*)()>::operator()<boost::_mfi::mf2<void, TCPConnection, boost::system::error_code const&, unsigned long>, boost::_bi::list2<boost::system::error_code const&, unsigned long const&> >(boost::_bi::type<void>, boost::_mfi::mf2<void, TCPConnection, boost::system::error_code const&, unsigned long>&, boost::_bi::list2<boost::system::error_code const&, unsigned long const&>&, int) (bind.hpp:392)
==26447== by 0x5812BD: void boost::_bi::bind_t<void, boost::_mfi::mf2<void, TCPConnection, boost::system::error_code const&, unsigned long>, boost::_bi::list3<boost::_bi::value<boost::shared_ptr<TCPConnection> >, boost::arg<1> (*)(), boost::arg<2> (*)()> >::operator()<boost::system::error_code, unsigned long>(boost::system::error_code const&, unsigned long const&) (bind_template.hpp:102)
==26447== Uninitialised value was created by a stack allocation
==26447== at 0x553EAA: ConceptGraph::makeHash() (ConceptGraph.hpp:258)
所以,我讀了各地了一下,發現我可以導入MEMCHECK,並要求特定的內存請求:
std::size_t makeHash ()
{
std::size_t tmp;
for (auto & concept : _concepts)
tmp += concept->Hash();
for (auto & relation : _relations)
tmp += relation->Hash();
for (auto & edge : _adjacency_list)
tmp += std::hash<std::size_t>()(edge.first->Hash() + edge.second->Hash());
_hash = std::hash<std::size_t>()(tmp);
VALGRIND_CHECK_MEM_IS_DEFINED (_hash, sizeof(std::size_t));
return _hash;
}
從該孔家當源自於實際問題的行是:
std::stringstream hash;
hash << graph->Hash();
我知道的是初始化,並確定。
這是什麼意思?
如果我理解正確,那麼它的一個警告字節可能會丟失?
這是一個誤報,還是我錯過了別的東西?
「tmp」未初始化而不是「散列」。 –