From c4ea4dc0dfe60cb34ac57ac9f533faf928e331cf Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 27 Dec 2015 13:16:46 +0100 Subject: [PATCH] Fix some warnings (looking like potential bugs) detected by cppcheck, (a few from a patch from Julien Nabet ), remove not used vars and a few coding style fixes. --- common/draw_panel.cpp | 15 ++++----------- eeschema/sch_sheet.cpp | 2 +- eeschema/sch_sheet_path.cpp | 2 +- pagelayout_editor/pl_editor_undo_redo.cpp | 6 +++--- utils/idftools/idf_cylinder.cpp | 2 +- utils/idftools/idf_helpers.cpp | 7 ++++--- utils/idftools/idf_parser.cpp | 4 ---- utils/idftools/vrml_layer.cpp | 3 --- 8 files changed, 14 insertions(+), 27 deletions(-) diff --git a/common/draw_panel.cpp b/common/draw_panel.cpp index cc53c2e992..23c97a2be7 100644 --- a/common/draw_panel.cpp +++ b/common/draw_panel.cpp @@ -725,8 +725,9 @@ void EDA_DRAW_PANEL::DrawGrid( wxDC* aDC ) org.y += KiROUND( gridSize.y ); // Use a pixel based draw to display grid. There are a lot of calls, so the cost is - // high and grid is slowly drawn on some platforms. Please note that this should - // always be enabled until the bitmap based solution below is fixed. + // high and grid is slowly drawn on some platforms. An other way using blit transfert was used, + // a long time ago, but it did not give very good results. + // The better way is highly dependent on the platform and the graphic card. #ifndef __WXMAC__ GRSetColorPen( aDC, GetParent()->GetGridColor() ); #else @@ -996,7 +997,7 @@ void EDA_DRAW_PANEL::OnMagnify( wxMouseEvent& event ) void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) { - int localrealbutt = 0, localbutt = 0; + int localbutt = 0; BASE_SCREEN* screen = GetScreen(); if( !screen ) @@ -1030,12 +1031,6 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) if( m_ignoreMouseEvents ) return; - if( event.LeftIsDown() ) - localrealbutt |= GR_M_LEFT_DOWN; - - if( event.MiddleIsDown() ) - localrealbutt |= GR_M_MIDDLE_DOWN; - if( event.LeftDown() ) localbutt = GR_M_LEFT_DOWN; @@ -1045,8 +1040,6 @@ void EDA_DRAW_PANEL::OnMouseEvent( wxMouseEvent& event ) if( event.MiddleDown() ) localbutt = GR_M_MIDDLE_DOWN; - localrealbutt |= localbutt; // compensation default wxGTK - INSTALL_UNBUFFERED_DC( DC, this ); DC.SetBackground( *wxBLACK_BRUSH ); diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index fc9d1e8809..8773625797 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -498,7 +498,7 @@ void SCH_SHEET::CleanupSheet() } if( HLabel == NULL ) // Hlabel not found: delete sheet label. - m_pins.erase( i ); + i = m_pins.erase( i ); else ++i; } diff --git a/eeschema/sch_sheet_path.cpp b/eeschema/sch_sheet_path.cpp index 3b720c624a..24dd861245 100644 --- a/eeschema/sch_sheet_path.cpp +++ b/eeschema/sch_sheet_path.cpp @@ -882,7 +882,7 @@ SCH_SHEET* SCH_SHEET_LIST::FindSheetByName( const wxString& aSheetName ) for( int i = 0; i < m_count; i++ ) { - sheet = m_list[i].FindSheetByName( aSheetName ); + SCH_SHEET* sheet = m_list[i].FindSheetByName( aSheetName ); if( sheet ) return sheet; diff --git a/pagelayout_editor/pl_editor_undo_redo.cpp b/pagelayout_editor/pl_editor_undo_redo.cpp index d1711e7c5c..de00b81cad 100644 --- a/pagelayout_editor/pl_editor_undo_redo.cpp +++ b/pagelayout_editor/pl_editor_undo_redo.cpp @@ -105,7 +105,7 @@ void PL_EDITOR_FRAME::GetLayoutFromRedoList( wxCommandEvent& event ) lastcmd = GetScreen()->PopCommandFromRedoList(); wrapper = lastcmd->PopItem(); - copyItem = (PL_ITEM_LAYOUT*)wrapper.GetItem(); + copyItem = static_cast( wrapper.GetItem() ); pglayout.SetPageLayout( TO_UTF8(copyItem->m_Layout) ); delete copyItem; @@ -136,7 +136,7 @@ void PL_EDITOR_FRAME::GetLayoutFromUndoList( wxCommandEvent& event ) lastcmd = GetScreen()->PopCommandFromUndoList(); wrapper = lastcmd->PopItem(); - copyItem = (PL_ITEM_LAYOUT*)wrapper.GetItem(); + copyItem = static_cast( wrapper.GetItem() ); pglayout.SetPageLayout( TO_UTF8(copyItem->m_Layout) ); delete copyItem; @@ -156,6 +156,6 @@ void PL_EDITOR_FRAME::RemoveLastCommandInUndoList() PICKED_ITEMS_LIST* lastcmd = GetScreen()->PopCommandFromUndoList(); ITEM_PICKER wrapper = lastcmd->PopItem(); - PL_ITEM_LAYOUT* copyItem = (PL_ITEM_LAYOUT*)wrapper.GetItem(); + PL_ITEM_LAYOUT* copyItem = static_cast( wrapper.GetItem() ); delete copyItem; } diff --git a/utils/idftools/idf_cylinder.cpp b/utils/idftools/idf_cylinder.cpp index e7870d48e6..0e5560bc5e 100644 --- a/utils/idftools/idf_cylinder.cpp +++ b/utils/idftools/idf_cylinder.cpp @@ -578,7 +578,7 @@ void make_hcyl( bool inch, bool axial, double dia, double length, fprintf( fp, ".END_ELECTRICAL\n" ); fclose( fp ); - return; + return; } diff --git a/utils/idftools/idf_helpers.cpp b/utils/idftools/idf_helpers.cpp index cad1852732..798ea0c058 100644 --- a/utils/idftools/idf_helpers.cpp +++ b/utils/idftools/idf_helpers.cpp @@ -83,7 +83,8 @@ bool IDF3::GetIDFString( const std::string& aLine, std::string& aIDFString, if( idx < 0 || idx >= len ) return false; - while( isspace( aLine[idx] ) && idx < len ) ++idx; + while( idx < len && isspace( aLine[idx] ) ) + ++idx; if( idx == len ) { @@ -95,7 +96,7 @@ bool IDF3::GetIDFString( const std::string& aLine, std::string& aIDFString, { hasQuotes = true; ++idx; - while( aLine[idx] != '"' && idx < len ) + while( idx < len && aLine[idx] != '"' ) ostr << aLine[idx++]; if( idx == len ) @@ -112,7 +113,7 @@ bool IDF3::GetIDFString( const std::string& aLine, std::string& aIDFString, { hasQuotes = false; - while( !isspace( aLine[idx] ) && idx < len ) + while( idx < len && !isspace( aLine[idx] ) ) ostr << aLine[idx++]; } diff --git a/utils/idftools/idf_parser.cpp b/utils/idftools/idf_parser.cpp index c4d3e4cf79..4167603c6a 100644 --- a/utils/idftools/idf_parser.cpp +++ b/utils/idftools/idf_parser.cpp @@ -2720,8 +2720,6 @@ bool IDF3_BOARD::ReadFile( const wxString& aFullFileName, bool aNoSubstituteOutl // 2. Check if a file with extension 'emp' exists and read it // 3. Open the specified filename and read it - std::string fname = TO_UTF8( aFullFileName ); - wxFileName brdname( aFullFileName ); wxFileName libname( aFullFileName ); @@ -3125,8 +3123,6 @@ bool IDF3_BOARD::WriteFile( const wxString& aFullFileName, bool aUnitMM, bool aF // 2. Write the *.emn file according to the IDFv3 spec // 3. Write the *.emp file according to the IDFv3 spec - std::string fname = TO_UTF8( aFullFileName ); - wxFileName brdname( aFullFileName ); wxFileName libname( aFullFileName ); diff --git a/utils/idftools/vrml_layer.cpp b/utils/idftools/vrml_layer.cpp index 5974371660..a8b4bb9466 100644 --- a/utils/idftools/vrml_layer.cpp +++ b/utils/idftools/vrml_layer.cpp @@ -1592,9 +1592,6 @@ int VRML_LAYER::checkNContours( bool holes ) if( contours.empty() ) return 0; - std::list::const_iterator begin; - std::list::const_iterator end; - for( size_t i = 0; i < contours.size(); ++i ) { if( contours[i]->size() < 3 )