4

这是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 ( percent < 0.2 )

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

4

2 回答 2

3

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

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

要更进一步,您需要知道该变量在哪里分配/声明。您可以从以下位置获取此信息:

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

这意味着在 musicwidget.cpp 的第 148 行中,您在 int(百分比)上创建了一个 new,但您没有对其进行初始化。你应该在那里发现你的错误。

题外话:在 int 上使用 new 通常不是一个好主意。如果可能的话,而是将其声明为变量

于 2012-12-25T15:12:38.833 回答
2

看起来 valgrind 传播了访问的未初始化值的使用,GetMPDSeekPerc()并在未初始化的值实际用于某事而不是仅仅传递它时报告错误。关于的消息Uninitialised value was created by a heap allocation ...直截了当地指出了未初始化值的来源。

于 2012-12-25T15:13:19.260 回答