New compiler warnings

Everything about development and the OpenMW source code.
Post Reply
User avatar
psi29a
Posts: 5355
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

New compiler warnings

Post by psi29a »

With the recent updates to travis, we now have access to gcc8 and clang6 which means we also have some new complains.

Feel free to have a look:
https://travis-ci.org/OpenMW/openmw/bui ... tification

From gcc8:

Code: Select all

/home/travis/build/OpenMW/openmw/components/contentselector/model/contentmodel.cpp: In member function ‘virtual QVariant ContentSelectorModel::ContentModel::data(const QModelIndex&, int) const’:
/home/travis/build/OpenMW/openmw/components/contentselector/model/contentmodel.cpp:171:86: warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
             return file->fileProperty(static_cast<const EsmFile::FileProperty>(column));
                                                                                      ^
From clang6:

Code: Select all

/home/travis/build/OpenMW/openmw/components/myguiplatform/myguirendermanager.cpp:138:91: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
                glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(MyGUI::Vertex), (char*)nullptr + 12);
                                                                           ~~~~~~~~~~~~~~ ^
/home/travis/build/OpenMW/openmw/components/myguiplatform/myguirendermanager.cpp:139:86: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
                glTexCoordPointer(2, GL_FLOAT, sizeof(MyGUI::Vertex), (char*)nullptr + 16);
                                                                      ~~~~~~~~~~~~~~ ^
 /home/travis/build/OpenMW/openmw/apps/wizard/existinginstallationpage.cpp:34:5: warning: Potential leak of memory pointed to by 'item'
    foreach (const QString &path, paths) {
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/qt4/QtCore/qglobal.h:2451:21: note: expanded from macro 'foreach'
#    define foreach Q_FOREACH
                    ^
/usr/include/qt4/QtCore/qglobal.h:2387:56: note: expanded from macro 'Q_FOREACH'
    for (variable = *_container_.i;; __extension__ ({--_container_.brk; break;}))
                                                       ^~~~~~~~~~~
1 warning generated.                                                                     

/home/travis/build/OpenMW/openmw/apps/opencs/model/world/infoselectwrapper.cpp:523:35: warning: unused variable 'InvalidRange' [-Wunused-variable]
    const std::pair<float, float> InvalidRange(FloatMax, FloatMin);
                                  ^
1 warning generated.

In file included from /home/travis/build/OpenMW/openmw/apps/opencs/model/world/idcompletionmanager.cpp:1:
In file included from /home/travis/build/OpenMW/openmw/apps/opencs/model/world/idcompletionmanager.hpp:5:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/map:61:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_map.h:63:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/tuple:39:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/array:39:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/stdexcept:39:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/string:52:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/basic_string.h:39:
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/ext/atomicity.h:67:29: warning: Use of memory after it is freed
    _Atomic_word __result = *__mem;
                            ^~~~~~
1 warning generated.

/home/travis/build/OpenMW/openmw/apps/opencs/view/widget/scenetoolbar.cpp:31:1: warning: Potential leak of memory pointed to by 'focusSceneShortcut'
}
^
1 warning generated.

/home/travis/build/OpenMW/openmw/apps/opencs/view/render/scenewidget.cpp:229:70: warning: Potential leak of memory pointed to by 'focusToolbarShortcut'
    CSMPrefs::Shortcut* renderStatsShortcut = new CSMPrefs::Shortcut("scene-render-stats", this);
                                                                     ^~~~~~~~~~~~~~~~~~~~
/home/travis/build/OpenMW/openmw/apps/opencs/view/render/scenewidget.cpp:231:1: warning: Potential leak of memory pointed to by 'renderStatsShortcut'
}
^
2 warnings generated.

/home/travis/build/OpenMW/openmw/apps/opencs/view/render/worldspacewidget.cpp:107:72: warning: Potential leak of memory pointed to by 'primaryEditShortcut'
    CSMPrefs::Shortcut* secondaryEditShortcut = new CSMPrefs::Shortcut("scene-edit-secondary", this);
                                                                       ^~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/OpenMW/openmw/apps/opencs/view/render/worldspacewidget.cpp:110:72: warning: Potential leak of memory pointed to by 'secondaryEditShortcut'
    CSMPrefs::Shortcut* primarySelectShortcut = new CSMPrefs::Shortcut("scene-select-primary", this);
                                                                       ^~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/OpenMW/openmw/apps/opencs/view/render/worldspacewidget.cpp:113:74: warning: Potential leak of memory pointed to by 'primarySelectShortcut'
    CSMPrefs::Shortcut* secondarySelectShortcut = new CSMPrefs::Shortcut("scene-select-secondary", this);
                                                                         ^~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/OpenMW/openmw/apps/opencs/view/render/worldspacewidget.cpp:116:64: warning: Potential leak of memory pointed to by 'secondarySelectShortcut'
    CSMPrefs::Shortcut* abortShortcut = new CSMPrefs::Shortcut("scene-edit-abort", this);
                                                               ^~~~~~~~~~~~~~~~~~
/home/travis/build/OpenMW/openmw/apps/opencs/view/render/worldspacewidget.cpp:119:20: warning: Potential leak of memory pointed to by 'abortShortcut'
    mInConstructor = false;
    ~~~~~~~~~~~~~~~^~~~~~~
5 warnings generated.

/home/travis/build/OpenMW/openmw/apps/opencs/view/render/pagedworldspacewidget.cpp:567:77: warning: Potential leak of memory pointed to by 'loadCameraCellShortcut'
    CSMPrefs::Shortcut* loadCameraEastCellShortcut = new CSMPrefs::Shortcut("scene-load-cam-eastcell", this);
                                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/OpenMW/openmw/apps/opencs/view/render/pagedworldspacewidget.cpp:570:78: warning: Potential leak of memory pointed to by 'loadCameraEastCellShortcut'
    CSMPrefs::Shortcut* loadCameraNorthCellShortcut = new CSMPrefs::Shortcut("scene-load-cam-northcell", this);
                                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/OpenMW/openmw/apps/opencs/view/render/pagedworldspacewidget.cpp:573:77: warning: Potential leak of memory pointed to by 'loadCameraNorthCellShortcut'
    CSMPrefs::Shortcut* loadCameraWestCellShortcut = new CSMPrefs::Shortcut("scene-load-cam-westcell", this);
                                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/OpenMW/openmw/apps/opencs/view/render/pagedworldspacewidget.cpp:576:78: warning: Potential leak of memory pointed to by 'loadCameraWestCellShortcut'
    CSMPrefs::Shortcut* loadCameraSouthCellShortcut = new CSMPrefs::Shortcut("scene-load-cam-southcell", this);
                                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/travis/build/OpenMW/openmw/apps/opencs/view/render/pagedworldspacewidget.cpp:578:1: warning: Potential leak of memory pointed to by 'loadCameraSouthCellShortcut'
}
^
5 warnings generated.

User avatar
akortunov
Posts: 899
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: New compiler warnings

Post by akortunov »

A typical suspicious case:

Code: Select all

    CSMPrefs::Shortcut* focusSceneShortcut = new CSMPrefs::Shortcut("scene-focus-toolbar", this);
    connect(focusSceneShortcut, SIGNAL(activated()), this, SIGNAL(focusSceneRequest()));
    return;
Should the connected focusSceneShortcut object be cleaned automatically, or there is a real memory leak?
In the latter case we should keep pointers to shortcuts in the field variables and delete objects in destructors.
User avatar
akortunov
Posts: 899
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: New compiler warnings

Post by akortunov »

Code: Select all

In file included from /home/travis/build/OpenMW/openmw/apps/opencs/model/world/idcompletionmanager.cpp:1:
In file included from /home/travis/build/OpenMW/openmw/apps/opencs/model/world/idcompletionmanager.hpp:5:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/map:61:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_map.h:63:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/tuple:39:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/array:39:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/stdexcept:39:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/string:52:
In file included from /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/basic_string.h:39:
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/ext/atomicity.h:67:29: warning: Use of memory after it is freed
    _Atomic_word __result = *__mem;
                            ^~~~~~
It seems this one is a false-positive and it should be fixed in the Clang 7.

As about other warnings, this PR should fix them.
User avatar
psi29a
Posts: 5355
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: New compiler warnings

Post by psi29a »

Sweet!
User avatar
akortunov
Posts: 899
Joined: 13 Mar 2017, 13:49
Location: Samara, Russian Federation

Re: New compiler warnings

Post by akortunov »

After some investigation I am inclined to think that "Potential leak of memory" spam is a false-positive too.
CSMPrefs::Shortcut is derived from QObject, and we assign this widget to the parent QObject.
During parent QObject destruction, Qt should destruct all child objects:
QObjects organize themselves in object trees. When you create a QObject with another object as parent, the object will automatically add itself to the parent's children() list. The parent takes ownership of the object; i.e., it will automatically delete its children in its destructor.
User avatar
psi29a
Posts: 5355
Joined: 29 Sep 2011, 10:13
Location: Belgium
Gitlab profile: https://gitlab.com/psi29a/
Contact:

Re: New compiler warnings

Post by psi29a »

Updated to clang7... got the following additional issues:

Code: Select all

/home/travis/build/OpenMW/openmw/components/nifosg/nifloader.cpp:425:21: warning: Access to field 'recType' results in a dereference of a null pointer (loaded from variable 'nifNode')
            switch (nifNode->recType)
                    ^~~~~~~~~~~~~~~~
1 warning generated.

/home/travis/build/OpenMW/openmw/components/myguiplatform/myguirendermanager.cpp:138:98: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
                glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(MyGUI::Vertex), static_cast<char*>(0) + 12);
                                                                           ~~~~~~~~~~~~~~~~~~~~~ ^
/home/travis/build/OpenMW/openmw/components/myguiplatform/myguirendermanager.cpp:139:93: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
                glTexCoordPointer(2, GL_FLOAT, sizeof(MyGUI::Vertex), static_cast<char*>(0) + 16);
                                                                      ~~~~~~~~~~~~~~~~~~~~~ ^
2 warnings generated.

In file included from /home/travis/build/OpenMW/openmw/apps/openmw/mwgui/bookpage.cpp:1:
/home/travis/build/OpenMW/openmw/apps/openmw/mwgui/bookpage.hpp:53:36: warning: Called C++ object pointer is null
            MyGUI::GlyphInfo* gi = font->getGlyphInfo(ch);
                                   ^~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

/home/travis/build/OpenMW/openmw/apps/openmw/mwgui/keyboardnavigation.cpp:28:10: warning: Called C++ object pointer is null
    if (!parent->getVisible() || !parent->getEnabled())
         ^~~~~~~~~~~~~~~~~~~~
1 warning generated.

/home/travis/build/OpenMW/openmw/apps/openmw/mwsound/ffmpeg_decoder.cpp:116:13: warning: Branch condition evaluates to a garbage value
        if (!got_frame || mFrame->nb_samples == 0)
            ^~~~~~~~~~
1 warning generated.
Post Reply