Browse Source

SYMBOL_LIBRARY_MANAGER: Enforce non-null via reference

All code paths in CreateLibrary and AddLibrary check that
the LIB_TABLE is non-null first.
jobs
John Beard 1 year ago
parent
commit
69889eff7c
  1. 6
      eeschema/symbol_editor/symbol_edit_frame.cpp
  2. 9
      eeschema/symbol_library_manager.cpp
  3. 6
      eeschema/symbol_library_manager.h
  4. 2
      eeschema/tools/sch_editor_control.cpp

6
eeschema/symbol_editor/symbol_edit_frame.cpp

@ -989,7 +989,7 @@ wxString SYMBOL_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
if( aCreateNew )
{
if( !m_libMgr->CreateLibrary( fn.GetFullPath(), libTable ) )
if( !m_libMgr->CreateLibrary( fn.GetFullPath(), *libTable ) )
{
DisplayError( this, wxString::Format( _( "Could not create the library file '%s'.\n"
"Make sure you have write permissions and "
@ -1000,7 +1000,7 @@ wxString SYMBOL_EDIT_FRAME::AddLibraryFile( bool aCreateNew )
}
else
{
if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
if( !m_libMgr->AddLibrary( fn.GetFullPath(), *libTable ) )
{
DisplayError( this, _( "Could not open the library file." ) );
return wxEmptyString;
@ -1038,7 +1038,7 @@ void SYMBOL_EDIT_FRAME::DdAddLibrary( wxString aLibFile )
return;
}
if( !m_libMgr->AddLibrary( fn.GetFullPath(), libTable ) )
if( !m_libMgr->AddLibrary( fn.GetFullPath(), *libTable ) )
{
DisplayError( this, _( "Could not open the library file." ) );
return;

9
eeschema/symbol_library_manager.cpp

@ -716,9 +716,8 @@ wxString SYMBOL_LIBRARY_MANAGER::getLibraryName( const wxString& aFilePath )
bool SYMBOL_LIBRARY_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate,
SYMBOL_LIB_TABLE* aTable )
SYMBOL_LIB_TABLE& aTable )
{
wxCHECK( aTable, false );
wxString libName = getLibraryName( aFilePath );
wxCHECK( !LibraryExists( libName ), false ); // either create or add an existing one
@ -732,7 +731,7 @@ bool SYMBOL_LIBRARY_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate
wxString typeName = SCH_IO_MGR::ShowType( schFileType );
SYMBOL_LIB_TABLE_ROW* libRow = new SYMBOL_LIB_TABLE_ROW( libName, relPath, typeName );
aTable->InsertRow( libRow );
aTable.InsertRow( libRow );
if( aCreate )
{
@ -740,11 +739,11 @@ bool SYMBOL_LIBRARY_MANAGER::addLibrary( const wxString& aFilePath, bool aCreate
try
{
aTable->CreateSymbolLib( libName );
aTable.CreateSymbolLib( libName );
}
catch( const IO_ERROR& )
{
aTable->RemoveRow( libRow );
aTable.RemoveRow( libRow );
return false;
}
}

6
eeschema/symbol_library_manager.h

@ -215,7 +215,7 @@ public:
/**
* Create an empty library and adds it to the library table. The library file is created.
*/
bool CreateLibrary( const wxString& aFilePath, SYMBOL_LIB_TABLE* aTable )
bool CreateLibrary( const wxString& aFilePath, SYMBOL_LIB_TABLE& aTable )
{
return addLibrary( aFilePath, true, aTable );
}
@ -223,7 +223,7 @@ public:
/**
* Add an existing library. The library is added to the library table as well.
*/
bool AddLibrary( const wxString& aFilePath, SYMBOL_LIB_TABLE* aTable )
bool AddLibrary( const wxString& aFilePath, SYMBOL_LIB_TABLE& aTable )
{
return addLibrary( aFilePath, false, aTable );
}
@ -375,7 +375,7 @@ protected:
static wxString getLibraryName( const wxString& aFilePath );
///< Helper function to add either existing or create new library
bool addLibrary( const wxString& aFilePath, bool aCreate, SYMBOL_LIB_TABLE* aTable );
bool addLibrary( const wxString& aFilePath, bool aCreate, SYMBOL_LIB_TABLE& aTable );
///< Return the current Symbol Library Table.

2
eeschema/tools/sch_editor_control.cpp

@ -410,7 +410,7 @@ int SCH_EDITOR_CONTROL::ExportSymbolsToLibrary( const TOOL_EVENT& aEvent )
if( fn.FileExists() )
wxRemoveFile( fn.GetFullPath() );
if( !mgr.CreateLibrary( fn.GetFullPath(), libTable ) )
if( !mgr.CreateLibrary( fn.GetFullPath(), *libTable ) )
{
DisplayError( m_frame, wxString::Format( _( "Could not add library '%s'." ),
targetLib ) );

Loading…
Cancel
Save