diff --git a/3d-viewer/3d_canvas/board_adapter.cpp b/3d-viewer/3d_canvas/board_adapter.cpp index fe2a37634e..951104f7a3 100644 --- a/3d-viewer/3d_canvas/board_adapter.cpp +++ b/3d-viewer/3d_canvas/board_adapter.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2015-2016 Mario Luzeiro - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -82,6 +82,7 @@ BOARD_ADAPTER::BOARD_ADAPTER() : m_IsPreviewer( false ), m_board( nullptr ), m_3dModelManager( nullptr ), + m_renderSettings( nullptr ), m_colors( nullptr ), m_layerZcoordTop(), m_layerZcoordBottom() diff --git a/common/eda_text.cpp b/common/eda_text.cpp index 0a6dafa0cd..071b07021d 100644 --- a/common/eda_text.cpp +++ b/common/eda_text.cpp @@ -92,7 +92,8 @@ GR_TEXT_V_ALIGN_T EDA_TEXT::MapVertJustify( int aVertJustify ) EDA_TEXT::EDA_TEXT( const wxString& text ) : m_text( text ), m_bounding_box_cache_valid( false ), - m_bounding_box_cache_line( -1 ) + m_bounding_box_cache_line( -1 ), + m_bounding_box_cache_inverted( false ) { int sz = Mils2iu( DEFAULT_SIZE_TEXT ); SetTextSize( wxSize( sz, sz ) ); @@ -122,6 +123,8 @@ EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText ) m_bounding_box_cache_valid = aText.m_bounding_box_cache_valid; m_bounding_box_cache = aText.m_bounding_box_cache; + m_bounding_box_cache_line = aText.m_bounding_box_cache_line; + m_bounding_box_cache_inverted = aText.m_bounding_box_cache_inverted; } diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index 200e4f29aa..e5f5411d6c 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -198,7 +198,7 @@ void DIALOG_ERC::updateDisplayedCounts() wxString msg; - if( m_ercRun ) + if( m_ercRun && m_markerProvider && m_ignoredList ) { msg.sprintf( m_violationsTitleTemplate, m_markerProvider->GetCount() ); m_notebook->SetPageText( 0, msg ); diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index b3f9436f3c..8778469a32 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -207,6 +207,8 @@ void LIB_PIN::print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset, LIB_SYMBOL* part = GetParent(); + wxCHECK( part && opts, /* void */ ); + /* Calculate pin orient taking in account the symbol orientation. */ int orient = PinDrawOrient( aTransform ); diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 36581e6e91..2a0f5c9447 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2015-2021 KiCad Developers, see change_log.txt for contributors. + * Copyright (C) 2015-2022 KiCad Developers, see change_log.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 @@ -376,6 +376,11 @@ void SCH_BASE_FRAME::RefreshSelection() void SCH_BASE_FRAME::AddToScreen( EDA_ITEM* aItem, SCH_SCREEN* aScreen ) { + // Null pointers will cause boost::ptr_vector to raise a boost::bad_pointer exception which + // will be unhandled. There is no valid reason to pass an invalid EDA_ITEM pointer to the + // screen append function. + wxCHECK( aItem != nullptr, /* voide */ ); + auto screen = aScreen; if( aScreen == nullptr ) diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index e13451850f..d083c35982 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -1059,6 +1059,8 @@ void SCH_SEXPR_PLUGIN::saveText( SCH_TEXT* aText, int aNestLevel ) SCH_LABEL_BASE* label = dynamic_cast( aText ); + wxCHECK( label, /* void */ ); + m_out->Print( aNestLevel, "(%s %s", getTextTypeToken( aText->Type() ), m_out->Quotew( aText->GetText() ).c_str() ); diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 637442d407..fd90272f56 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -1253,6 +1253,9 @@ int SCH_SHEET::ComparePageNum( const wxString& aPageNumberA, const wxString& aPa // If not numeric, then sort as strings using natural sort int result = StrNumCmp( aPageNumberA, aPageNumberB ); + // Divide by zero bad. + wxCHECK( result != 0, 0 ); + result = result / std::abs( result ); return result; diff --git a/eeschema/sch_sheet_path.h b/eeschema/sch_sheet_path.h index d3254be44c..bf832b4ee4 100644 --- a/eeschema/sch_sheet_path.h +++ b/eeschema/sch_sheet_path.h @@ -44,7 +44,7 @@ struct SYMBOL_INSTANCE_REFERENCE // Things that can be annotated: wxString m_Reference; - int m_Unit; + int m_Unit = 1; // Things that can be back-annotated: wxString m_Value; diff --git a/eeschema/symbol_editor/symbol_library_manager.cpp b/eeschema/symbol_editor/symbol_library_manager.cpp index dc1cd6b86c..b24e4f9db2 100644 --- a/eeschema/symbol_editor/symbol_library_manager.cpp +++ b/eeschema/symbol_editor/symbol_library_manager.cpp @@ -1014,6 +1014,9 @@ bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer( std::shared_ptr symbol = GetBuffer( entry ); + + wxCHECK2( symbol, continue ); + LIB_SYMBOL* derivedSymbol = new LIB_SYMBOL( *symbol->GetSymbol() ); derivedSymbol->SetParent( parentSymbol ); result = aLibTable->SaveSymbol( m_libName, derivedSymbol ); @@ -1165,6 +1168,9 @@ bool SYMBOL_LIBRARY_MANAGER::LIB_BUFFER::SaveBuffer( std::shared_ptr symbol = GetBuffer( entry ); + + wxCHECK2( symbol, continue ); + LIB_SYMBOL* derivedSymbol = new LIB_SYMBOL( *symbol->GetSymbol() ); derivedSymbol->SetParent( parentSymbol ); diff --git a/eeschema/symbol_library.cpp b/eeschema/symbol_library.cpp index d2d9675c03..2d89185bcb 100644 --- a/eeschema/symbol_library.cpp +++ b/eeschema/symbol_library.cpp @@ -62,6 +62,7 @@ SYMBOL_LIB::SYMBOL_LIB( SCH_LIB_TYPE aType, const wxString& aFileName, m_plugin.reset( SCH_IO_MGR::FindPlugin( m_pluginType ) ); m_properties = std::make_unique(); + m_mod_hash = 0; } diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 9eb0b787a2..947602cc37 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -287,6 +287,8 @@ bool SCH_EDIT_TOOL::Init() { const SCH_ITEM* schItem = dynamic_cast( item ); + wxCHECK( schItem, false ); + return ( schItem->HasLineStroke() && schItem->IsConnectable() ) || item->Type() == SCH_JUNCTION_T; } ) ) @@ -1635,6 +1637,8 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) { const SCH_ITEM* schItem = dynamic_cast( item ); + wxCHECK( schItem, false ); + return ( schItem->HasLineStroke() && schItem->IsConnectable() ) || item->Type() == SCH_JUNCTION_T; } ) ) @@ -1728,6 +1732,8 @@ int SCH_EDIT_TOOL::ChangeTextType( const TOOL_EVENT& aEvent ) default: UNIMPLEMENTED_FOR( wxString::Format( "%d.", convertTo ) ); break; } + wxCHECK2( newtext, continue ); + // Copy the old text item settings to the new one. Justifications are not copied // because they are not used in labels. Justifications will be set to default value // in the new text item type. diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index 07b926bf00..e3119c610f 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -108,6 +108,8 @@ COMMIT& BOARD_COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO aModFlag void BOARD_COMMIT::dirtyIntersectingZones( BOARD_ITEM* item ) { + wxCHECK( item, /* void */ ); + if( item->Type() == PCB_FOOTPRINT_T ) { static_cast( item )->RunOnChildren( @@ -163,6 +165,8 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags ) std::vector bulkRemovedItems; std::vector itemsChanged; + wxCHECK( frame, /* void */ ); + if( Empty() ) return; diff --git a/pcbnew/drc/drc_test_provider_disallow.cpp b/pcbnew/drc/drc_test_provider_disallow.cpp index 46addefbd9..6961e250c0 100644 --- a/pcbnew/drc/drc_test_provider_disallow.cpp +++ b/pcbnew/drc/drc_test_provider_disallow.cpp @@ -237,6 +237,8 @@ bool DRC_TEST_PROVIDER_DISALLOW::Run() if( zone && zone->GetIsRuleArea() ) return true; + wxCHECK( pad, false ); + item->ClearFlags( HOLE_PROXY ); // Just in case checkDisallow( item ); @@ -256,6 +258,7 @@ bool DRC_TEST_PROVIDER_DISALLOW::Run() { checkDisallow( item ); } + item->ClearFlags( HOLE_PROXY ); } } diff --git a/pcbnew/drc/drc_test_provider_misc.cpp b/pcbnew/drc/drc_test_provider_misc.cpp index cd73577a98..bab3f49925 100644 --- a/pcbnew/drc/drc_test_provider_misc.cpp +++ b/pcbnew/drc/drc_test_provider_misc.cpp @@ -287,6 +287,8 @@ void DRC_TEST_PROVIDER_MISC::testTextVars() BOARD_ITEM* boardItem = dynamic_cast( item ); EDA_TEXT* text = dynamic_cast( boardItem ); + wxCHECK( boardItem, false ); + if( text && text->GetShownText().Matches( wxT( "*${*}*" ) ) ) { std::shared_ptrdrcItem = DRC_ITEM::Create( DRCE_UNRESOLVED_VARIABLE ); @@ -294,6 +296,7 @@ void DRC_TEST_PROVIDER_MISC::testTextVars() reportViolation( drcItem, boardItem->GetPosition(), boardItem->GetLayer() ); } + return true; } ); diff --git a/pcbnew/pcb_base_frame.cpp b/pcbnew/pcb_base_frame.cpp index f4ecb3078b..6d4db2404e 100644 --- a/pcbnew/pcb_base_frame.cpp +++ b/pcbnew/pcb_base_frame.cpp @@ -4,7 +4,7 @@ * Copyright (C) 2018 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck * Copyright (C) 2011 Wayne Stambaugh - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 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 @@ -441,7 +441,17 @@ void PCB_BASE_FRAME::FocusOnItem( BOARD_ITEM* aItem, PCB_LAYER_ID aLayer ) while( !itemPoly.IsEmpty() ) { focusPt = (wxPoint) itemPoly.BBox().Centre(); - itemPoly.Deflate( step, 4, SHAPE_POLY_SET::CHAMFER_ACUTE_CORNERS ); + + try + { + itemPoly.Deflate( step, 4, SHAPE_POLY_SET::CHAMFER_ACUTE_CORNERS ); + } + 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() ); + } } FocusOnLocation( focusPt ); diff --git a/pcbnew/plugins/pcad/pcb_callbacks.h b/pcbnew/plugins/pcad/pcb_callbacks.h index dfc466a4cf..c0db80ae13 100644 --- a/pcbnew/plugins/pcad/pcb_callbacks.h +++ b/pcbnew/plugins/pcad/pcb_callbacks.h @@ -3,7 +3,7 @@ * * Copyright (C) 2007, 2008 Lubo Racko * Copyright (C) 2007, 2008, 2012 Alexander Lunev - * Copyright (C) 2012 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2012, 2022 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 @@ -44,7 +44,7 @@ enum LAYER_TYPE_T struct TLAYER { PCB_LAYER_ID KiCadLayer; - LAYER_TYPE_T layerType; + LAYER_TYPE_T layerType = LAYER_TYPE_SIGNAL; wxString netNameRef; }; diff --git a/pcbnew/teardrop/teardrop_utils.cpp b/pcbnew/teardrop/teardrop_utils.cpp index 13773ccfe0..68c1d8ff11 100644 --- a/pcbnew/teardrop/teardrop_utils.cpp +++ b/pcbnew/teardrop/teardrop_utils.cpp @@ -435,7 +435,8 @@ bool TEARDROP_MANAGER::ComputePointsOnPadVia( TEARDROP_PARAMETERS* aCurrParams, } else // Only PADS can have a not round shape { - wxASSERT( pad ); + wxCHECK( pad, false ); + force_clip_shape = true; preferred_height = aViaPad.m_Width * aCurrParams->m_HeightRatio; diff --git a/pcbnew/tools/pcb_selection_tool.cpp b/pcbnew/tools/pcb_selection_tool.cpp index 760b8c9368..03c80bd80e 100644 --- a/pcbnew/tools/pcb_selection_tool.cpp +++ b/pcbnew/tools/pcb_selection_tool.cpp @@ -1875,9 +1875,9 @@ void PCB_SELECTION_TOOL::FindItem( BOARD_ITEM* aItem ) //Let's refocus because there is an algortihm to avoid dialogs in there. m_frame->FocusOnLocation( aItem->GetCenter() ); } - - delete screenRect; } + + delete screenRect; } // Inform other potentially interested tools m_toolMgr->ProcessEvent( EVENTS::SelectedEvent ); diff --git a/pcbnew/widgets/appearance_controls.cpp b/pcbnew/widgets/appearance_controls.cpp index a56393277a..c7cfbde020 100644 --- a/pcbnew/widgets/appearance_controls.cpp +++ b/pcbnew/widgets/appearance_controls.cpp @@ -2659,8 +2659,9 @@ void APPEARANCE_CONTROLS::onViewportChanged( wxCommandEvent& aEvent ) { VIEWPORT* viewport = static_cast( m_cbViewports->GetClientData( index ) ); - if( viewport ) - doApplyViewport( *viewport ); + wxCHECK( viewport, /* void */ ); + + doApplyViewport( *viewport ); if( !viewport->name.IsEmpty() ) {