试图了解valgrind输出

时间:2012-12-25 14:58:49

标签: c++ qt valgrind

这是valgrind输出..

Conditional jump or move depends on uninitialised value(s)
in RingsWidget::UpdateSeekBar() in ringswidget.cpp:514
1: RingsWidget::UpdateSeekBar() in <a href="file:///media/dipesh/Documents/Qt-projects/NomadDesktop-build-Desktop-Debug/../NomadDesktop/ringswidget.cpp:514" >ringswidget.cpp:514</a>
2: RingsWidget::UpdateRings() in <a href="file:///media/dipesh/Documents/Qt-projects/NomadDesktop-build-Desktop-Debug/../NomadDesktop/ringswidget.cpp:138" >ringswidget.cpp:138</a>
3: RingsWidget::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) in <a href="file:///media/dipesh/Documents/Qt-projects/NomadDesktop-build-Desktop-Debug/moc_ringswidget.cpp:49" >/media/dipesh/Documents/Qt-projects/NomadDesktop-build-Desktop-Debug/moc_ringswidget.cpp:49</a>
4: QMetaObject::activate(QObject*, QMetaObject const*, int, void**) in /usr/lib/libQtCore.so.4.8.4
5: QObject::event(QEvent*) in /usr/lib/libQtCore.so.4.8.4
6: QApplicationPrivate::notify_helper(QObject*, QEvent*) in /usr/lib/libQtGui.so.4.8.4
7: QApplication::notify(QObject*, QEvent*) in /usr/lib/libQtGui.so.4.8.4
8: QCoreApplication::notifyInternal(QObject*, QEvent*) in /usr/lib/libQtCore.so.4.8.4
9: /usr/lib/libQtCore.so.4.8.4
10: /usr/lib/libQtCore.so.4.8.4
11: g_main_context_dispatch in /usr/lib/libglib-2.0.so.0.3400.3
12: /usr/lib/libglib-2.0.so.0.3400.3
13: g_main_context_iteration in /usr/lib/libglib-2.0.so.0.3400.3
14: QEventDispatcherGlib::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) in /usr/lib/libQtCore.so.4.8.4
15: /usr/lib/libQtGui.so.4.8.4
16: QEventLoop::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) in /usr/lib/libQtCore.so.4.8.4
17: QEventLoop::exec(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) in /usr/lib/libQtCore.so.4.8.4
18: QCoreApplication::exec() in /usr/lib/libQtCore.so.4.8.4
19: main in <a href="file:///media/dipesh/Documents/Qt-projects/NomadDesktop-build-Desktop-Debug/../NomadDesktop/main.cpp:19" >main.cpp:19</a>

Uninitialised value was created by a heap allocation  1: operator new(unsigned long) in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
2: MusicWidget::MusicWidget(QWidget*) in <a href="file:///media/dipesh/Documents/Qt-projects/NomadDesktop-build-Desktop-Debug/../NomadDesktop/musicwidget.cpp:148" >musicwidget.cpp:148</a>
3: NomadWindow::Initialize() in <a href="file:///media/dipesh/Documents/Qt-projects/NomadDesktop-build-Desktop-Debug/../NomadDesktop/nomadwindow.cpp:127" >nomadwindow.cpp:127</a>
4: NomadWindow::NomadWindow(QWidget*) in <a href="file:///media/dipesh/Documents/Qt-projects/NomadDesktop-build-Desktop-Debug/../NomadDesktop/nomadwindow.cpp:27" >nomadwindow.cpp:27</a>
5: main in <a href="file:///media/dipesh/Documents/Qt-projects/NomadDesktop-build-Desktop-Debug/../NomadDesktop/main.cpp:15" >main.cpp:15</a>

这是代码..

511 NomadWindow *par = (NomadWindow*)parent();
512 float percentage = par->GetMusicWidget()->GetMPDSeekPerc();
513 settings[5].operator []("value") = percentage;
514 if ( percentage < 0.2 )
515     settings[5].operator []("fg_alpha") = 0.2;
516 else
517     settings[5].operator []("fg_alpha") = percentage;

valgrind输出来自第514行     if(百分比<0.2)

我做错了什么?提前谢谢..

2 个答案:

答案 0 :(得分:3)

  

条件跳转或移动取决于未初始化的值

这通常意味着你有一个if测试未初始化的值。因此if的结果是随机的。

要进一步了解,您需要知道此变量的分配/声明位置。您可以从以下网址获取此信息:

  

未初始化的值是由堆分配1:operator new(unsigned long)在...中创建的   [...] musicwidget.cpp中的MusicWidget :: MusicWidget(QWidget *):148

这意味着在musicwidget.cpp第148行中,你在int(百分比)上创建了一个新的但你没有初始化它。你应该在那里找到错误。

偏离主题:在int上使用new通常不是一个好主意。而是在可能的情况下将其声明为变量

答案 1 :(得分:2)

看起来好像valgrind传播了GetMPDSeekPerc()中访问的未初始化值的使用,并且当未初始化的值实际用于某些内容时报告错误,而不是仅仅传递它。关于Uninitialised value was created by a heap allocation ...的消息非常坦率地指出了未初始化值的来源。