From 112e8e7ccbcd3f299e94ee7433a309829c3c7f95 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand <seth@kipro-pcb.com> Date: Wed, 29 Jan 2025 00:00:11 -0600 Subject: [PATCH] Remove a few more crashers Need to check SYM_LIB_TABLE_ENTRY for null but need to check FP_LIB_TABLE_ENTRY for throwing --- eeschema/widgets/panel_symbol_chooser.cpp | 4 +++- pcbnew/footprint_libraries_utils.cpp | 11 ++++++++++- pcbnew/fp_tree_synchronizing_adapter.cpp | 20 +++++++++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/eeschema/widgets/panel_symbol_chooser.cpp b/eeschema/widgets/panel_symbol_chooser.cpp index 99a7069923..35085f87ec 100644 --- a/eeschema/widgets/panel_symbol_chooser.cpp +++ b/eeschema/widgets/panel_symbol_chooser.cpp @@ -99,7 +99,9 @@ PANEL_SYMBOL_CHOOSER::PANEL_SYMBOL_CHOOSER( SCH_BASE_FRAME* aFrame, wxWindow* aP bool pinned = alg::contains( session.pinned_symbol_libs, nickname ) || alg::contains( project.m_PinnedSymbolLibs, nickname ); - if( libs->FindRow( nickname )->GetIsVisible() ) + SYMBOL_LIB_TABLE_ROW* row = libs->FindRow( nickname ); + + if( row && row->GetIsVisible() ) adapter->AddLibrary( nickname, pinned ); } } diff --git a/pcbnew/footprint_libraries_utils.cpp b/pcbnew/footprint_libraries_utils.cpp index ed6fd1bc57..6b8113382f 100644 --- a/pcbnew/footprint_libraries_utils.cpp +++ b/pcbnew/footprint_libraries_utils.cpp @@ -527,10 +527,19 @@ bool FOOTPRINT_EDIT_FRAME::DeleteFootprintFromLibrary( const LIB_ID& aFPID, bool wxString nickname = aFPID.GetLibNickname(); wxString fpname = aFPID.GetLibItemName(); + wxString libfullname; // Legacy libraries are readable, but modifying legacy format is not allowed // So prompt the user if he try to delete a footprint from a legacy lib - wxString libfullname = PROJECT_PCB::PcbFootprintLibs( &Prj() )->FindRow( nickname )->GetFullURI(); + try + { + libfullname = PROJECT_PCB::PcbFootprintLibs( &Prj() )->FindRow( nickname )->GetFullURI(); + } + catch( ... ) + { + // If we can't find the nickname, stop here + return false; + } if( PCB_IO_MGR::GuessPluginTypeFromLibPath( libfullname ) == PCB_IO_MGR::LEGACY ) { diff --git a/pcbnew/fp_tree_synchronizing_adapter.cpp b/pcbnew/fp_tree_synchronizing_adapter.cpp index 91514128b1..347f3cee5f 100644 --- a/pcbnew/fp_tree_synchronizing_adapter.cpp +++ b/pcbnew/fp_tree_synchronizing_adapter.cpp @@ -79,16 +79,26 @@ void FP_TREE_SYNCHRONIZING_ADAPTER::Sync( FP_LIB_TABLE* aLibs ) { const wxString& name = it->get()->m_Name; - // Remove the library if it no longer exists or it exists in both the global and the - // project library but the project library entry is disabled. - if( !m_libs->HasLibrary( name, true ) - || m_libs->FindRow( name, true ) != m_libs->FindRow( name, false ) ) + try { + // Remove the library if it no longer exists or it exists in both the global and the + // project library but the project library entry is disabled. + if( !m_libs->HasLibrary( name, true ) + || m_libs->FindRow( name, true ) != m_libs->FindRow( name, false ) ) + { + it = deleteLibrary( it ); + continue; + } + + updateLibrary( *(LIB_TREE_NODE_LIBRARY*) it->get() ); + } + catch( ... ) + { + // If the library isn't found, remove it it = deleteLibrary( it ); continue; } - updateLibrary( *(LIB_TREE_NODE_LIBRARY*) it->get() ); ++it; }