From 99121b75c96c142c6566b891dbf8cab4a16ca0ec Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 26 Jul 2020 19:30:24 +0200 Subject: [PATCH] LGTM: [skip ci] fix: Local variable hides global variable A local variable or parameter that hides a global variable of the same name. This may be confusing. Consider renaming one of the variables. --- src/Gui/BitmapFactory.cpp | 4 ++-- src/Gui/SoFCDB.cpp | 20 +++++++++--------- src/Gui/ViewProviderPyImp.cpp | 32 +++-------------------------- src/Mod/Drawing/App/FeaturePage.cpp | 2 -- 4 files changed, 15 insertions(+), 43 deletions(-) diff --git a/src/Gui/BitmapFactory.cpp b/src/Gui/BitmapFactory.cpp index 32dc01b75f..5f7f711555 100644 --- a/src/Gui/BitmapFactory.cpp +++ b/src/Gui/BitmapFactory.cpp @@ -57,7 +57,7 @@ using namespace Gui; /* XPM */ -static const char *px[]={ +static const char *not_found[]={ "24 24 2 1", "# c #000000", ". c #ffffff", @@ -293,7 +293,7 @@ QPixmap BitmapFactoryInst::pixmap(const char* name) const } Base::Console().Warning("Cannot find icon: %s\n", name); - return QPixmap(px); + return QPixmap(not_found); } QPixmap BitmapFactoryInst::pixmapFromSvg(const char* name, const QSize& size) const diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index d66b3c269a..bcde577c83 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -216,32 +216,32 @@ void Gui::SoFCDB::finish() } // buffer acrobatics for inventor **************************************************** -static char * buffer; -static size_t buffer_size = 0; +static char * static_buffer; +static size_t static_buffer_size = 0; static std::string cReturnString; static void * buffer_realloc(void * bufptr, size_t size) { - buffer = (char *)realloc(bufptr, size); - buffer_size = size; - return buffer; + static_buffer = (char *)realloc(bufptr, size); + static_buffer_size = size; + return static_buffer; } const std::string& Gui::SoFCDB::writeNodesToString(SoNode * root) { SoOutput out; - buffer = (char *)malloc(1024); - buffer_size = 1024; - out.setBuffer(buffer, buffer_size, buffer_realloc); + static_buffer = (char *)malloc(1024); + static_buffer_size = 1024; + out.setBuffer(static_buffer, static_buffer_size, buffer_realloc); if (root && root->getTypeId().isDerivedFrom(SoVRMLParent::getClassTypeId())) out.setHeaderString("#VRML V2.0 utf8"); SoWriteAction wa(&out); wa.apply(root); - cReturnString = buffer; - free(buffer); + cReturnString = static_buffer; + free(static_buffer); return cReturnString; } diff --git a/src/Gui/ViewProviderPyImp.cpp b/src/Gui/ViewProviderPyImp.cpp index f7d12e8803..11cae60f63 100644 --- a/src/Gui/ViewProviderPyImp.cpp +++ b/src/Gui/ViewProviderPyImp.cpp @@ -34,6 +34,7 @@ #include #include #include +#include "SoFCDB.h" #include "ViewProvider.h" #include "WidgetFactory.h" @@ -621,37 +622,10 @@ void ViewProviderPy::setSwitchNode(Py::Object) } -static char * buffer; -static size_t buffer_size = 0; - -static void * -buffer_realloc(void * bufptr, size_t size) -{ - buffer = (char *)realloc(bufptr, size); - buffer_size = size; - return buffer; -} - -static SbString -buffer_writeaction(SoNode * root) -{ - SoOutput out; - buffer = (char *)malloc(1024); - buffer_size = 1024; - out.setBuffer(buffer, buffer_size, buffer_realloc); - - SoWriteAction wa(&out); - wa.apply(root); - - SbString s(buffer); - free(buffer); - return s; -} - Py::String ViewProviderPy::getIV(void) const { - SbString buf = buffer_writeaction(getViewProviderPtr()->getRoot()); - return Py::String(buf.getString()); + std::string buf = Gui::SoFCDB::writeNodesToString(getViewProviderPtr()->getRoot()); + return Py::String(buf); } Py::Object ViewProviderPy::getIcon(void) const diff --git a/src/Mod/Drawing/App/FeaturePage.cpp b/src/Mod/Drawing/App/FeaturePage.cpp index 12f83296ed..70ad678eac 100644 --- a/src/Mod/Drawing/App/FeaturePage.cpp +++ b/src/Mod/Drawing/App/FeaturePage.cpp @@ -50,8 +50,6 @@ using namespace std; PROPERTY_SOURCE(Drawing::FeaturePage, App::DocumentObjectGroup) -const char *group = "Drawing view"; - FeaturePage::FeaturePage(void) : numChildren(0) { static const char *group = "Drawing view";