An attempt to understand the output of valgrind

Here is the result of 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 output of valgrind is output from line 514 if (in percent <0.2)

What am I doing wrong? Thanks in advance.

+4
source share
2 answers

It seems that valgrind is propagating the use of the uninitialized value available in GetMPDSeekPerc() and reporting an error when the uninitialized value is actually used for something, rather than just passing it. The Uninitialised value was created by a heap allocation ... directly indicates where the uninitialized value comes from.

+2
source

Conditional jump or move depends on uninitialized value (s)

This means what you have if it checks for a value that is not initialized. Therefore, the result of if is random.

To go further, you need to know where this variable is distributed / declared. You can get this information:

An uninitialized value was created by heap distribution 1: the new (unsigned long) operator in ... MusicWidget :: MusicWidget (QWidget *) in [...] musicwidget.cpp: 148

This means that in musicwidget.cpp, line 148, you create a new value in int (percent), but you do not initialize it. You should find a mistake there.

Disable topic: using new in int is usually not a good idea. Rather declare it as a variable, if possible

+3
source

All Articles