Jo2003 / cd2netmd_gui

A tool like Sonys NetMD Simple Burner
GNU General Public License v3.0
43 stars 7 forks source link

Fix possible null ptr dereferencing #4

Closed rigomate closed 2 years ago

rigomate commented 2 years ago

Clang-tidy caught the following issue:

/home/runner/work/cd2netmd_gui/cd2netmd_gui/cmdtreemodel.cpp:167:13: warning: Called C++ object pointer is null [clang-analyzer-core.CallAndMessage]
            pGroup->appendChild(pTrack);
            ^
/home/runner/work/cd2netmd_gui/cd2netmd_gui/cmdtreemodel.cpp:31:5: note: Calling 'CMDTreeModel::setupModelData'
    setupModelData();
    ^
/home/runner/work/cd2netmd_gui/cd2netmd_gui/cmdtreemodel.cpp:126:5: note: 'pGroup' initialized to a null pointer value
    CTreeItem*  pGroup = nullptr;
    ^
/home/runner/work/cd2netmd_gui/cd2netmd_gui/cmdtreemodel.cpp:136:13: note: Assuming the condition is false
        if (trackGroup.empty())
            ^
/home/runner/work/cd2netmd_gui/cd2netmd_gui/cmdtreemodel.cpp:136:9: note: Taking false branch
        if (trackGroup.empty())
        ^
/home/runner/work/cd2netmd_gui/cd2netmd_gui/cmdtreemodel.cpp:152:13: note: Taking false branch
            if (trackGroup != currGrp)
            ^
/home/runner/work/cd2netmd_gui/cd2netmd_gui/cmdtreemodel.cpp:167:13: note: Called C++ object pointer is null
            pGroup->appendChild(pTrack);
            ^

This is a a simple and stupid fix to not get Undefined Behavior by calling dereferencing a null pointer.

rigomate commented 2 years ago

I have modified the initial fix as it had a small flaw, therefore the force push.