使用valgrind时出现以下错误:
==3099== Conditional jump or move depends on uninitialised value(s)
==3099== at 0x40BA65D: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (in /usr/lib/libstdc++.so.6.0.14)
==3099== by 0x40BA98C: 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, long) const (in /usr/lib/libstdc++.so.6.0.14)
==3099== by 0x40C5A98: std::ostream& std::ostream::_M_insert<long>(long) (in /usr/lib/libstdc++.so.6.0.14)
==3099== by 0x40C5C13: std::ostream::operator<<(int) (in /usr/lib/libstdc++.so.6.0.14)
==3099== by 0x80A5CC6: Ser::method() (in /home/user)
==3099== by 0x80BCA61: bool Ser() (in /home/user)
==3099== by 0x80958D1: Ser::Select() (in /home/user)
==3099== by 0x804B85D: main (in /home/user)
==3099==
==3099== Use of uninitialised value of size 4
==3099== at 0x40BA12E: ??? (in /usr/lib/libstdc++.so.6.0.14)
==3099== by 0x40BA693: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (in /usr/lib/libstdc++.so.6.0.14)
==3099== by 0x40BA98C: 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, long) const (in /usr/lib/libstdc++.so.6.0.14)
==3099== by 0x40C5A98: std::ostream& std::ostream::_M_insert<long>(long) (in /usr/lib/libstdc++.so.6.0.14)
==3099== by 0x40C5C13: std::ostream::operator<<(int) (in /usr/lib/libstdc++.so.6.0.14)
==3099== by 0x80A5CC6: Ser::method() (in /home/user)
==3099== by 0x80BCA61: bool Ser::Call() (in /home//user)
==3099== by 0x80958D1: Ser::Select() (in /home/user)
==3099== by 0x804B85D: main (in /home/user)
这是什么意思? 错误在哪里?
答案 0 :(得分:0)
此错误表示您在初始化之前使用了一些变量。您似乎在int
中打印未初始化的Ser::method()
值。您应该在打印前对其进行初始化。