News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

warning: 'parent' may be used uninitialized when building ToolsPlus\shellpropert

Started by ollydbg, May 03, 2021, 04:02:36 PM

Previous topic - Next topic

ollydbg

When building with GCC 11.1 compiler, I got such warning:


[ 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:
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

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

should be

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

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

ollydbg


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. :)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

oBFusCATed

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

ollydbg

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.