[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kwrite-devel
Subject:    Re: Uninitialized config values
From:       Dominik Haumann <dhaumann () kde ! org>
Date:       2013-11-16 21:13:59
Message-ID: 14907849.Ct2nWWcDjW () eriador
[Download RAW message or body]

On Saturday 16 November 2013 21:53:56 Milian Wolff wrote:
> Hey all,
> 
> whenever I look at kate in valgrind, I see a ton of warnings about
> uninitialized variables, e.g.:
> 
> ==21033== Conditional jump or move depends on uninitialised value(s)
> ==21033==    at 0x2CA3851D: KateViewInternal::eventFilter(QObject*, QEvent*)
> (kateviewinternal.cpp:2198)
> ==21033==    by 0x7FEC025:
> QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*)
> (in /usr/lib/libQtCore.so.4.8.5)
> ==21033==    by 0x873910B: QApplicationPrivate::notify_helper(QObject*,
> QEvent*) (in /usr/lib/libQtGui.so.4.8.5)
> ==21033==    by 0x8740940: QApplication::notify(QObject*, QEvent*) (in
> /usr/lib/libQtGui.so.4.8.5)
> ==21033==    by 0x77CA839: KApplication::notify(QObject*, QEvent*) (in
> /usr/lib/libkdeui.so.5.11.3)
> ==21033==    by 0x7FEBEBC: QCoreApplication::notifyInternal(QObject*,
> QEvent*) (in /usr/lib/libQtCore.so.4.8.5)
> ==21033==    by 0x876A4BB: ??? (in /usr/lib/libQtGui.so.4.8.5)
> ==21033==    by 0x87409C2: QApplication::notify(QObject*, QEvent*) (in
> /usr/lib/libQtGui.so.4.8.5)
> ==21033==    by 0x77CA839: KApplication::notify(QObject*, QEvent*) (in
> /usr/lib/libkdeui.so.5.11.3)
> ==21033==    by 0x7FEBEBC: QCoreApplication::notifyInternal(QObject*,
> QEvent*) (in /usr/lib/libQtCore.so.4.8.5)
> ==21033==    by 0x87D36A8: ??? (in /usr/lib/libQtGui.so.4.8.5)
> ==21033==    by 0x87D3A48: ??? (in /usr/lib/libQtGui.so.4.8.5)
> ==21033==    by 0x87AF9BE: QApplication::x11ProcessEvent(_XEvent*) (in
> /usr/lib/libQtGui.so.4.8.5)
> ==21033==    by 0x87D61B1: ??? (in /usr/lib/libQtGui.so.4.8.5)
> ==21033==    by 0xEEF6255: g_main_context_dispatch (in
> /usr/lib/libglib-2.0.so.0.3800.1)
> ==21033==    by 0xEEF65A7: ??? (in /usr/lib/libglib-2.0.so.0.3800.1)
> ==21033==    by 0xEEF664B: g_main_context_iteration (in
> /usr/lib/libglib-2.0.so.0.3800.1)
> ==21033==    by 0x8018B24:
> QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)
> (in /usr/lib/libQtCore.so.4.8.5)
> ==21033==    by 0x87D6265: ??? (in /usr/lib/libQtGui.so.4.8.5)
> ==21033==    by 0x7FEAB1E:
> QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (in
> /usr/lib/libQtCore.so.4.8.5)
> ==21033==    by 0x7FEAE14:
> QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (in
> /usr/lib/libQtCore.so.4.8.5)
> ==21033==    by 0x7FEFF4A: QCoreApplication::exec() (in
> /usr/lib/libQtCore.so.4.8.5)
> ==21033==    by 0x412B81: main (main.cpp:566)
> ==21033==  Uninitialised value was created by a heap allocation
> ==21033==    at 0x4C27CC2: operator new(unsigned long) (in
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==21033==    by 0x2CAFD29E: KateGlobal::KateGlobal() (kateglobal.cpp:167)
> ==21033==    by 0x2CAFE9EE: KateGlobal::self() (kateglobal.cpp:465)
> ==21033==    by 0x405BC30: KateFactory::editor() (katefactory.cpp:53)
> ==21033==    by 0x53C08B7: KDevelop::PartController::editorPart() const
> (partcontroller.cpp:128)
> ==21033==    by 0x2BCA7CE3: SnippetPlugin::SnippetPlugin(QObject*,
> QList<QVariant> const&) (snippetplugin.cpp:90)
> ==21033==    by 0x2BCAAA8E: QObject*
> KPluginFactory::createInstance<SnippetPlugin, QObject>(QWidget*, QObject*,
> QList<QVariant> const&) (kpluginfactory.h:477)
> ==21033==    by 0x503D072: KPluginFactory::create(char const*, QWidget*,
> QObject*, QList<QVariant> const&, QString const&) (in
> /usr/lib/libkdecore.so.5.11.3)
> ==21033==    by 0x53968DA: KDevelop::IPlugin*
> KPluginFactory::create<KDevelop::IPlugin>(QWidget*, QObject*, QString
> const&, QList<QVariant> const&) (kpluginfactory.h:531)
> ==21033==    by 0x539663C: KDevelop::IPlugin*
> KService::createInstance<KDevelop::IPlugin>(QWidget*, QObject*,
> QList<QVariant> const&, QString*) const (kservice.h:573)
> ==21033==    by 0x539633A: KDevelop::IPlugin*
> KServiceTypeTrader::createInstanceFromQuery<KDevelop::IPlugin>(QString
> const&, QWidget*, QObject*, QString const&, QList<QVariant> const&,
> QString*) (kservicetypetrader.h:186)
> ==21033==    by 0x5394ED1: KDevelop::IPlugin*
> KServiceTypeTrader::createInstanceFromQuery<KDevelop::IPlugin>(QString
> const&, QString const&, QObject*, QList<QVariant> const&, QString*)
> (kservicetypetrader.h:157)
> ==21033==    by 0x538FF39:
> KDevelop::PluginController::loadPluginInternal(QString const&)
> (plugincontroller.cpp:432)
> ==21033==    by 0x5390D92: KDevelop::PluginController::initialize()
> (plugincontroller.cpp:263)
> ==21033==    by 0x539A6CF:
> KDevelop::CorePrivate::initialize(KDevelop::Core::Setup, QString)
> (core.cpp:244)
> ==21033==    by 0x539B042: KDevelop::Core::initialize(KSplashScreen*,
> KDevelop::Core::Setup, QString const&) (core.cpp:331)
> ==21033==    by 0x411222: main (main.cpp:469)

Can you please disable word wrap when pasting such a trace. It's a pain to 
read that (and you know it) ;)

> As far as I can see this is really an issue. In kateconfig.cpp the two ctors
> of KateViewConfig only initialize the *Set booleans. The actual config
> variables will stay uninitialized. But these are then later blindly
> accessed from the global KateViewConfig.
> 
> What is the proper way to fix this? I somehow doubt this is wrong for all
> config variables, so where is the place where the values are initialized?

I once stumbled over this as well. I guess since valgrind complains, this is a 
real issue?

I think the idea is: all global instances of the KateConfig objects 
(KateViewConfig, KateRenderConfig, KateDocumentConfig) read the settings from 
the global config by calling readConfig() in the constructors. Hence, the 
properties of the global config objects *should* all bet set.

Let's have a look at
KateRendererConfig::KateRendererConfig()
...
  , m_showIndentationLinesSet (true)
{
  readConfig();
}

KateRendererConfig::readConfig()
{
  setShowIndentationLines(config.read("the key", false));
}

Now, let's look into:

void KateRendererConfig::setShowIndentationLines (bool on)
{
  if (m_showIndentationLinesSet && m_showIndentationLines == on)
...
}

Here, this if is important: if it's already set, and m_showIndentationLines is 
accidently the same value as on, then all is fine and nothing has to be done.

Valgrind complains here, since m_showIndentationLines was never initialized, 
i.e. it has a random value.

But as you can see, this random value is caught correctly, and therefore this 
should not be an issue.

Does that make sense so far?


Now your question how to fix this: Initialize all variables of the global 
instances. The initialization value does not matter, because it's immediately 
overwritten by readConfig().

Greetings,
Dominik
_______________________________________________
KWrite-Devel mailing list
KWrite-Devel@kde.org
https://mail.kde.org/mailman/listinfo/kwrite-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic