Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: ollydbg on May 03, 2021, 04:02:36 pm

Title: warning: 'parent' may be used uninitialized when building ToolsPlus\shellpropert
Post by: ollydbg on May 03, 2021, 04:02:36 pm
When building with GCC 11.1 compiler, I got such warning:

Code
[ 71.4%] g++.exe -Wall -pipe -mthreads -fmessage-length=0 -fexceptions -DWXUSINGDLL -DHAVE_W32API_H -D__WXMSW__ -D_WIN64 -DcbDEBUG -DNOPCH -DwxUSE_UNICODE -DBUILDING_PLUGIN -std=gnu++11 -g -I..\..\..\include -I..\..\..\include\tinyxml -I..\..\..\sdk\wxscintilla\include -Id:\code\wxWidgets-3.1.5\include -Id:\code\wxWidgets-3.1.5\lib\gcc_dll\mswu -c D:\code\cbsource\codeblocks_sf\src\plugins\contrib\ToolsPlus\shellproperties.cpp -o ..\..\..\.objs31_64\plugins\contrib\ToolsPlus\shellproperties.o
D:\code\cbsource\codeblocks_sf\src\plugins\contrib\ToolsPlus\se_globals.cpp: In function 'wxString GetParentDir(const wxString&)':
D:\code\cbsource\codeblocks_sf\src\plugins\contrib\ToolsPlus\se_globals.cpp:5:21: warning: 'parent' may be used uninitialized [-Wmaybe-uninitialized]
    5 |     wxString parent=wxFileName(parent).GetPath(0);
      |                     ^~~~~~~~~~~~~~~~~~
In file included from D:\code\cbsource\codeblocks_sf\src\plugins\contrib\ToolsPlus\se_globals.h:12,
                 from D:\code\cbsource\codeblocks_sf\src\plugins\contrib\ToolsPlus\se_globals.cpp:1:
d:\code\wxWidgets-3.1.5\include/wx/filename.h:138:5: note: by argument 2 of type 'const wxString&' to 'wxFileName::wxFileName(const wxString&, wxPathFormat)' declared here
  138 |     wxFileName( const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE )
      |     ^~~~~~~~~~
D:\code\cbsource\codeblocks_sf\src\plugins\contrib\ToolsPlus\se_globals.cpp:5:14: note: 'parent' declared here
    5 |     wxString parent=wxFileName(parent).GetPath(0);
      |              ^~~~~~

I see the code is:
Code
wxString GetParentDir(const wxString &path)
{
    wxString parent=wxFileName(parent).GetPath(0);
    if(path==parent||parent.IsEmpty())
        return wxEmptyString;
    else
        return parent;
}

So, this is a bug?
I think

Code
wxString parent=wxFileName(parent).GetPath(0);

should be

Code
wxString parent=wxFileName(path).GetPath(0);
?

Title: Re: warning: 'parent' may be used uninitialized when building ToolsPlus\shellpropert
Post by: ollydbg on May 03, 2021, 04:10:27 pm
Code
D:\code\cbsource\codeblocks_sf\src\plugins\contrib\FileManager\se_globals.cpp: In function 'wxString GetParentDir(const wxString&)':
D:\code\cbsource\codeblocks_sf\src\plugins\contrib\FileManager\se_globals.cpp:6:21: warning: 'parent' may be used uninitialized [-Wmaybe-uninitialized]
    6 |     wxString parent=wxFileName(parent).GetPath(0);
      |                     ^~~~~~~~~~~~~~~~~~
In file included from D:\code\cbsource\codeblocks_sf\src\plugins\contrib\FileManager\se_globals.h:12,
                 from D:\code\cbsource\codeblocks_sf\src\plugins\contrib\FileManager\se_globals.cpp:2:
d:\code\wxWidgets-3.1.5\include/wx/filename.h:138:5: note: by argument 2 of type 'const wxString&' to 'wxFileName::wxFileName(const wxString&, wxPathFormat)' declared here
  138 |     wxFileName( const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE )
      |     ^~~~~~~~~~
D:\code\cbsource\codeblocks_sf\src\plugins\contrib\FileManager\se_globals.cpp:6:14: note: 'parent' declared here
    6 |     wxString parent=wxFileName(parent).GetPath(0);
      |              ^~~~~~


I see there is a similar warning in FileManager\se_globals.cpp.

There are two "se_globals.cpp" in our code base. :)
Title: Re: warning: 'parent' may be used uninitialized when building ToolsPlus\shellpropert
Post by: oBFusCATed on May 03, 2021, 04:41:14 pm
Just fix it.
Title: Re: warning: 'parent' may be used uninitialized when building ToolsPlus\shellpropert
Post by: ollydbg on May 04, 2021, 05:16:47 am
Just fix it.

Fixed in r12318.