简体   繁体   English

试图了解valgrind输出

[英]Trying to understand valgrind output

Here is the valgrind output.. 这是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>

Here is the code.. 这是代码..

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;

The valgrind output is from the line 514 if ( percentage < 0.2 ) 如果(百分比<0.2),valgrind输出来自第514行

What is it that i'm doing wrong? 我做错了什么? Thanks in advance.. 提前致谢..

Conditional jump or move depends on uninitialised value(s) 条件跳转或移动取决于未初始化的值

This means in general that you have an if that tests a value that is not initialized. 这通常意味着您有一个if测试未初始化的值。 The result of the if is therefore random. 因此if的结果是随机的。

To go further you need to know where this variable is allocated/declared. 要进一步了解,您需要知道此变量的分配/声明位置。 You can get this information from : 您可以从以下位置获取此信息:

Uninitialised value was created by a heap allocation 1: operator new(unsigned long) in ... MusicWidget::MusicWidget(QWidget*) in [...] musicwidget.cpp:148 未初始化的值是由一个堆分配1:operator new(unsigned long)创建的...... MusicWidget :: MusicWidget中的MusicWidget :: MusicWidget(QWidget *):148

That means that in musicwidget.cpp, line 148, you make a new on a int (the percentage) but you don't initialize it. 这意味着在musicwidget.cpp第148行中,你在int(百分比)上创建一个新的,但是你没有初始化它。 You should find you error there. 你应该在那里找到你的错误。

Off topic: using new on an int usually not a good idea. 偏离主题:在int上使用new通常不是一个好主意。 Rather declare it as a variable if possible 而是在可能的情况下将其声明为变量

It looks as if valgrind propagates the use of the uninitialized value accessed in GetMPDSeekPerc() and reports an error when the uninitialized value is actually used for something rather than than just passing it along. 看起来好像valgrind传播了GetMPDSeekPerc()访问的未初始化值的使用,并且当未初始化的值实际用于某些内容时报告错误,而不是仅仅传递它。 The message about Uninitialised value was created by a heap allocation ... quite bluntly points to where the uninitialized value is coming from. 有关Uninitialised value was created by a heap allocation ...的消息Uninitialised value was created by a heap allocation ...非常直截了当地指向未初始化值的来源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM