gpt4 book ai didi

c++ - 精确定位 "conditional jump or move depends on uninitialized value(s)"valgrind 消息

转载 作者:IT老高 更新时间:2023-10-28 11:30:28 24 4
gpt4 key购买 nike

所以我从 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 侦探工作的情况下捕获错误值的最佳方法是什么?

更新:

我发现了问题所在,但奇怪的是,第一次使用 bad 值时 valgrind 没有报告。它被用于乘法函数:

movespeed = stat.speedfactor * speedfac * currentbendfactor.val;

其中 speedfac 是一个统一的 float 。但是,当时没有报告它,直到要打印该值时我才收到错误.. valgrind 是否有设置来更改此行为?

最佳答案

使用 valgrind 选项 --track-origins=yes让它跟踪未初始化值的来源。这会使其变慢并占用更多内存,但如果您需要追踪未初始化值的来源,这将非常有用。

更新:关于报告未初始化值的点,the valgrind manual states :

It is important to understand that your program can copy around junk (uninitialised) data as much as it likes. Memcheck observes this and keeps track of the data, but does not complain. A complaint is issued only when your program attempts to make use of uninitialised data in a way that might affect your program's externally-visible behaviour.

来自Valgrind FAQ :

As for eager reporting of copies of uninitialised memory values, this has been suggested multiple times. Unfortunately, almost all programs legitimately copy uninitialised memory values around (because compilers pad structs to preserve alignment) and eager checking leads to hundreds of false positives. Therefore Memcheck does not support eager checking at this time.

关于c++ - 精确定位 "conditional jump or move depends on uninitialized value(s)"valgrind 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2612447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com