因此,我从valgrind那里得到了一些神秘的未初始化的值消息,关于错误值的起源一直是个谜。
似乎valgrind显示的是最终使用统一值的位置,而不是未初始化值的来源。
==11366== Conditional jump or move depends on uninitialised value(s)
==11366== at 0x43CAE4F: __printf_fp (in /lib/tls/i686/cmov/libc-2.7.so)
==11366== by 0x43C6563: vfprintf (in /lib/tls/i686/cmov/libc-2.7.so)
==11366== by 0x43EAC03: vsnprintf (in /lib/tls/i686/cmov/libc-2.7.so)
==11366== by 0x42D475B: (within /usr/lib/libstdc++.so.6.0.9)
==11366== by 0x42E2C9B: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_float<double>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, char, double) const (in /usr/lib/libstdc++.so.6.0.9)
==11366== by 0x42E31B4: 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, double) const (in /usr/lib/libstdc++.so.6.0.9)
==11366== by 0x42EE56F: std::ostream& std::ostream::_M_insert<double>(double) (in /usr/lib/libstdc++.so.6.0.9)
==11366== by 0x81109ED: Snake::SnakeBody::syncBodyPos() (ostream:221)
==11366== by 0x810B9F1: Snake::Snake::update() (snake.cpp:257)
==11366== by 0x81113C1: SnakeApp::updateState() (snakeapp.cpp:224)
==11366== by 0x8120351: RoenGL::updateState() (roengl.cpp:1180)
==11366== by 0x81E87D9: Roensachs::update() (rs.cpp:321)
可以看出,它变得非常隐晦。.特别是因为当它由Class :: MethodX说时,它有时直接指向ostream等。也许这是由于优化?
==11366== by 0x81109ED: Snake::SnakeBody::syncBodyPos() (ostream:221)
就这样 有什么我想念的吗?在不必诉诸于超长的printf侦探工作的情况下捕捉不良价值的最佳方法是什么?
更新:
我发现了问题所在,但奇怪的是,当首次使用该错误值时,valgrind并未报告该错误。它用于乘法功能:
movespeed = stat.speedfactor * speedfac * currentbendfactor.val;
speedfac是一个单元化的浮点数。但是,当时没有报告,并且直到要打印该值时才出现错误。.是否为valgrind设置了更改此行为的方法?