From 9b70308f5c4393a33c0048dc0e1c4da6e96ae3a4 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 11 Jun 2022 22:28:42 +0100 Subject: [PATCH] Nullptr defensive code. Fixes https://gitlab.com/kicad/code/kicad/issues/11690 --- pcbnew/footprint_viewer_frame.cpp | 6 ++++- pcbnew/tools/footprint_editor_control.cpp | 31 +++++++++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/pcbnew/footprint_viewer_frame.cpp b/pcbnew/footprint_viewer_frame.cpp index e74707918e..efedaa1fe6 100644 --- a/pcbnew/footprint_viewer_frame.cpp +++ b/pcbnew/footprint_viewer_frame.cpp @@ -247,7 +247,11 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent id.SetLibNickname( getCurNickname() ); id.SetLibItemName( getCurFootprintName() ); - GetBoard()->Add( loadFootprint( id ) ); + + FOOTPRINT* footprint = loadFootprint( id ); + + if( footprint ) + GetBoard()->Add( footprint ); } drawPanel->DisplayBoard( m_pcb ); diff --git a/pcbnew/tools/footprint_editor_control.cpp b/pcbnew/tools/footprint_editor_control.cpp index 8d7acdc090..ba6fd63567 100644 --- a/pcbnew/tools/footprint_editor_control.cpp +++ b/pcbnew/tools/footprint_editor_control.cpp @@ -441,24 +441,27 @@ int FOOTPRINT_EDITOR_CONTROL::RenameFootprint( const TOOL_EVENT& aEvent ) { footprint = m_frame->LoadFootprint( fpID ); - try + if( footprint ) { - footprint->SetFPID( LIB_ID( libraryName, newName ) ); + try + { + footprint->SetFPID( LIB_ID( libraryName, newName ) ); - if( footprint->GetValue() == oldName ) - footprint->SetValue( newName ); + if( footprint->GetValue() == oldName ) + footprint->SetValue( newName ); - m_frame->SaveFootprintInLibrary( footprint, libraryName ); + m_frame->SaveFootprintInLibrary( footprint, libraryName ); - m_frame->Prj().PcbFootprintLibs()->FootprintDelete( libraryName, oldName ); - } - catch( const IO_ERROR& ioe ) - { - DisplayError( m_frame, ioe.What() ); - } - catch( ... ) - { - // Best efforts... + m_frame->Prj().PcbFootprintLibs()->FootprintDelete( libraryName, oldName ); + } + catch( const IO_ERROR& ioe ) + { + DisplayError( m_frame, ioe.What() ); + } + catch( ... ) + { + // Best efforts... + } } }