gpt4 book ai didi

c++ - 我应该担心 "Conditional jump or move depends on uninitialised value(s)"吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:53:44 25 4
gpt4 key购买 nike

如果您使用过 Memcheck(来自 Valgrind),您可能会熟悉这条消息...

Conditional jump or move depends on uninitialized value(s)

我读过这方面的内容,它只会在您使用未初始化的值时发生。

MyClass s;
s.DoStuff();

这会起作用,因为 s 是自动初始化的...所以如果是这种情况,并且它起作用了,为什么 Memcheck 告诉我它未初始化?应该忽略该消息吗?

也许我误解了错误指向我的位置。从 Valgrind 手册中,实际的错误片段是......

int main()
{
int x;
printf ("x = %d\n", x);
}

但是,在我的代码中,我看不到类似的东西。但是,我注意到 Memcheck 向我显示堆栈跟踪顶部的函数是一个虚函数;这可能与它有关吗?

==14446== Conditional jump or move depends on uninitialised value(s)
==14446== at 0x414164: vimrid::glut::GlutApplication::FinishRender() (GlutApplication.cpp:120)
==14446== by 0x422434: vimrid::demos::filterdemos::FilterDemo3::Render() (FilterDemo3.cpp:260)
==14446== by 0x412D3D: vimrid::VimridApplication::UpdateAndRender() (VimridApplication.cpp:93)
==14446== by 0x4144BA: vimrid::glut::GlutApplication::glutHandleDisplay() (GlutApplication.cpp:201)
==14446== by 0x41486A: vimrid::glut::GlutApplication::glutCallbackDisplay() (GlutApplication.cpp:277)
==14446== by 0x54D9FAA: (within /usr/lib64/libglut.so.3.8.0)
==14446== by 0x54DDA4A: fgEnumWindows (in /usr/lib64/libglut.so.3.8.0)
==14446== by 0x54DA4A3: glutMainLoopEvent (in /usr/lib64/libglut.so.3.8.0)
==14446== by 0x54DAEB5: glutMainLoop (in /usr/lib64/libglut.so.3.8.0)
==14446== by 0x413FF8: vimrid::glut::GlutApplication::Run() (GlutApplication.cpp:112)
==14446== by 0x41249D: vimrid::Launcher::runDemo(vimrid::VimridSettings&) (Launcher.cpp:150)
==14446== by 0x412767: vimrid::Launcher::Launch(int, char**) (Launcher.cpp:62)

更新 1:

我查看了 GlutApplication.cpp:120,看起来未初始化的变量被传递给该行上的函数。很简单!

最佳答案

您可以将标志 --track-origins=yes 添加到 valgrind,它会为您提供有关未初始化数据源的信息。它运行速度较慢,但​​很有帮助。

来源:Valgrind User Manual

关于c++ - 我应该担心 "Conditional jump or move depends on uninitialised value(s)"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/765913/

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