Nullptr defensive code.

Fixes https://gitlab.com/kicad/code/kicad/issues/11690
This commit is contained in:
Jeff Young 2022-06-11 22:28:42 +01:00
parent 4f3cfdc92e
commit 9b70308f5c
2 changed files with 22 additions and 15 deletions

View File

@ -247,7 +247,11 @@ FOOTPRINT_VIEWER_FRAME::FOOTPRINT_VIEWER_FRAME( KIWAY* aKiway, wxWindow* aParent
id.SetLibNickname( getCurNickname() ); id.SetLibNickname( getCurNickname() );
id.SetLibItemName( getCurFootprintName() ); id.SetLibItemName( getCurFootprintName() );
GetBoard()->Add( loadFootprint( id ) );
FOOTPRINT* footprint = loadFootprint( id );
if( footprint )
GetBoard()->Add( footprint );
} }
drawPanel->DisplayBoard( m_pcb ); drawPanel->DisplayBoard( m_pcb );

View File

@ -441,24 +441,27 @@ int FOOTPRINT_EDITOR_CONTROL::RenameFootprint( const TOOL_EVENT& aEvent )
{ {
footprint = m_frame->LoadFootprint( fpID ); 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 ) if( footprint->GetValue() == oldName )
footprint->SetValue( newName ); footprint->SetValue( newName );
m_frame->SaveFootprintInLibrary( footprint, libraryName ); m_frame->SaveFootprintInLibrary( footprint, libraryName );
m_frame->Prj().PcbFootprintLibs()->FootprintDelete( libraryName, oldName ); m_frame->Prj().PcbFootprintLibs()->FootprintDelete( libraryName, oldName );
} }
catch( const IO_ERROR& ioe ) catch( const IO_ERROR& ioe )
{ {
DisplayError( m_frame, ioe.What() ); DisplayError( m_frame, ioe.What() );
} }
catch( ... ) catch( ... )
{ {
// Best efforts... // Best efforts...
}
} }
} }