From 53f5d616aac665d7c81c297f00da0da74b7e3892 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 13 Nov 2021 11:38:19 -0500 Subject: [PATCH] Coverity issue fixes. --- eeschema/connection_graph.cpp | 8 ++++++-- eeschema/sch_edit_frame.cpp | 13 ++++++++++++- eeschema/tools/ee_selection_tool.cpp | 14 +++++++++++++- include/widgets/wx_splitter_window.h | 6 ++++-- pcbnew/footprint_editor_settings.cpp | 6 +++++- pcbnew/pcb_base_frame.cpp | 14 ++++++++++++-- pcbnew/tools/drawing_tool.cpp | 3 +++ pcbnew/tools/pcb_selection_tool.cpp | 11 ++++++++++- 8 files changed, 65 insertions(+), 10 deletions(-) diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index 0a2b7d337c..69d1a6fbee 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -2155,6 +2155,9 @@ int CONNECTION_GRAPH::RunERC() for( CONNECTION_SUBGRAPH* subgraph : m_subgraphs ) { + // There shouldn't be any null sub-graph pointers. + wxCHECK2( subgraph, continue ); + // Graph is supposed to be up-to-date before calling RunERC() wxASSERT( !subgraph->m_dirty ); @@ -2238,13 +2241,14 @@ int CONNECTION_GRAPH::RunERC() bool CONNECTION_GRAPH::ercCheckMultipleDrivers( const CONNECTION_SUBGRAPH* aSubgraph ) { + wxCHECK( aSubgraph, false ); /* * This was changed late in 6.0 to fix https://gitlab.com/kicad/code/kicad/-/issues/9367 * so I'm going to leave the original code in for just a little while. If anyone comes * across this in 7.0 development (or later), feel free to delete. */ #if 0 - if( aSubgraph && aSubgraph->m_second_driver ) + if( aSubgraph->m_second_driver ) { SCH_ITEM* primary = aSubgraph->m_first_driver; SCH_ITEM* secondary = aSubgraph->m_second_driver; @@ -2270,7 +2274,7 @@ bool CONNECTION_GRAPH::ercCheckMultipleDrivers( const CONNECTION_SUBGRAPH* aSubg return false; } #else - if( aSubgraph && aSubgraph->m_multiple_drivers ) + if( aSubgraph->m_multiple_drivers ) { for( SCH_ITEM* driver : aSubgraph->m_drivers ) { diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 2a4feebf66..f0a688e40c 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -327,7 +327,18 @@ SCH_EDIT_FRAME::~SCH_EDIT_FRAME() // Close the project if we are standalone, so it gets cleaned up properly if( Kiface().IsSingle() ) - GetSettingsManager()->UnloadProject( &Prj(), false ); + { + try + { + GetSettingsManager()->UnloadProject( &Prj(), false ); + } + catch( const nlohmann::detail::type_error& exc ) + { + // This may be overkill and could be an assertion but we are more likely to + // find any settings manager errors this way. + wxLogError( wxT( "Settings exception '%s' occurred." ), exc.what() ); + } + } } diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 32e3c33c95..5035f18fc4 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -56,6 +56,8 @@ #include #include #include +#include + SELECTION_CONDITION EE_CONDITIONS::SingleSymbol = []( const SELECTION& aSel ) { @@ -1044,7 +1046,17 @@ void EE_SELECTION_TOOL::GuessSelectionCandidates( EE_COLLECTOR& collector, const } else if( symbol ) { - bbox = symbol->GetBodyBoundingBox(); + try + { + bbox = symbol->GetBodyBoundingBox(); + } + catch( const boost::bad_pointer& exc ) + { + // This may be overkill and could be an assertion but we are more likely to + // find any boost pointer container errors this way. + wxLogError( wxT( "Boost bad pointer exception '%s' occurred." ), exc.what() ); + } + SHAPE_RECT rect( bbox.GetPosition(), bbox.GetWidth(), bbox.GetHeight() ); if( bbox.Contains( pos ) ) diff --git a/include/widgets/wx_splitter_window.h b/include/widgets/wx_splitter_window.h index cd5453d331..298dbd4e8e 100644 --- a/include/widgets/wx_splitter_window.h +++ b/include/widgets/wx_splitter_window.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2018, 2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,7 +32,9 @@ public: WX_SPLITTER_WINDOW( wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxSP_3D, const wxString& name = wxT( "splitter" ) ) : - wxSplitterWindow( parent, id, pos, size, style, name ) + wxSplitterWindow( parent, id, pos, size, style, name ), + m_minFirstPane( -1 ), + m_minSecondPane( -1 ) { this->Connect( wxEVT_SIZE, wxSizeEventHandler( WX_SPLITTER_WINDOW::OnSize ) ); } diff --git a/pcbnew/footprint_editor_settings.cpp b/pcbnew/footprint_editor_settings.cpp index 9b229599fb..afd3420d90 100644 --- a/pcbnew/footprint_editor_settings.cpp +++ b/pcbnew/footprint_editor_settings.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Jon Evans - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -53,6 +53,10 @@ FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS() : m_MagneticItems.tracks = MAGNETIC_OPTIONS::NO_EFFECT; m_MagneticItems.graphics = true; + m_AuiPanels.appearance_panel_tab = 0; + m_AuiPanels.right_panel_width = -1; + m_AuiPanels.show_layer_manager = true; + m_params.emplace_back( new PARAM( "window.lib_width", &m_LibWidth, 250 ) ); diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index d252280ae4..bf81b44180 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -284,7 +284,16 @@ void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer ) SHAPE_POLY_SET dialogPoly( BOX2D( view->ToWorld( dialogPos, true ), view->ToWorld( dialog->GetSize(), false ) ) ); - viewportPoly.BooleanSubtract( dialogPoly, SHAPE_POLY_SET::PM_FAST ); + try + { + viewportPoly.BooleanSubtract( dialogPoly, SHAPE_POLY_SET::PM_FAST ); + } + catch( const ClipperLib::clipperException& exc ) + { + // This may be overkill and could be an assertion but we are more likely to find + // any clipper errors this way. + wxLogError( wxT( "Clipper library exception '%s' occurred." ), exc.what() ); + } } SHAPE_POLY_SET itemPoly, clippedPoly; @@ -324,7 +333,8 @@ void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer ) itemPoly.Append( item_bbox.GetOrigin() ); itemPoly.Append( item_bbox.GetOrigin() + VECTOR2I( item_bbox.GetWidth(), 0 ) ); itemPoly.Append( item_bbox.GetOrigin() + VECTOR2I( 0, item_bbox.GetHeight() ) ); - itemPoly.Append( item_bbox.GetOrigin() + VECTOR2I( item_bbox.GetWidth(), item_bbox.GetHeight() ) ); + itemPoly.Append( item_bbox.GetOrigin() + VECTOR2I( item_bbox.GetWidth(), + item_bbox.GetHeight() ) ); break; } } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index a2ec5bbe3d..29737453f8 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -1749,6 +1749,9 @@ static void updateArcFromConstructionMgr( const KIGFX::PREVIEW::ARC_GEOM_MANAGER bool DRAWING_TOOL::drawArc( const std::string& aTool, PCB_SHAPE** aGraphic, bool aImmediateMode ) { PCB_SHAPE*& graphic = *aGraphic; + + wxCHECK( graphic, 0 ); + PCB_LAYER_ID drawingLayer = m_frame->GetActiveLayer(); m_lineWidth = getSegmentWidth( drawingLayer ); diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index d2e889c170..f365815769 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -2327,7 +2327,16 @@ int PCB_SELECTION_TOOL::hitTestDistance( const wxPoint& aWhere, BOARD_ITEM* aIte FOOTPRINT* footprint = static_cast( aItem ); EDA_RECT bbox = footprint->GetBoundingBox( false, false ); - footprint->GetBoundingHull().Collide( loc, aMaxDistance, &distance ); + try + { + footprint->GetBoundingHull().Collide( loc, aMaxDistance, &distance ); + } + catch( const ClipperLib::clipperException& exc ) + { + // This may be overkill and could be an assertion but we are more likely to find + // any clipper errors this way. + wxLogError( wxT( "Clipper library exception '%s' occurred." ), exc.what() ); + } // Consider footprints larger than the viewport only as a last resort if( bbox.GetHeight() > viewport.GetHeight() || bbox.GetWidth() > viewport.GetWidth() )