Coverity warning fix.

This fixes all of the warnings cause by using std::weak_ptr objects when
recursing the symbol inheritance tree to retrieve the root symbol.  The
issue is that the weak pointers are not guaranteed to be valid for each
recursion because the lock will go out of scope.  Using a std::shared_ptr
object will ensure the lock is valid until it goes out of scope.
This commit is contained in:
Wayne Stambaugh 2023-10-28 13:15:45 -04:00
parent f6dc67dc3b
commit 30ba1b8007
7 changed files with 13 additions and 14 deletions

View File

@ -624,11 +624,10 @@ int EESCHEMA_JOBS_HANDLER::doSymExportSvg( JOB_SYM_EXPORT_SVG* aSvgJob,
// if the symbol is an alias, then the draw items are stored in the root symbol
if( symbol->IsAlias() )
{
LIB_SYMBOL_SPTR parent = symbol->GetRootSymbol().lock();
wxCHECK( parent, CLI::EXIT_CODES::ERR_UNKNOWN );
symbolToPlot = parent.get();
if( LIB_SYMBOL_SPTR parent = symbol->GetRootSymbol() )
symbolToPlot = parent.get();
else
wxCHECK( false, CLI::EXIT_CODES::ERR_UNKNOWN );
}
if( aSvgJob->m_includeHiddenPins )

View File

@ -534,7 +534,7 @@ int LIB_SYMBOL::Compare( const LIB_SYMBOL& aRhs, int aCompareFlags, REPORTER* aR
}
LIB_SYMBOL_REF LIB_SYMBOL::GetRootSymbol() const
LIB_SYMBOL_SPTR LIB_SYMBOL::GetRootSymbol() const
{
const LIB_SYMBOL_SPTR sp = m_parent.lock();
@ -2047,4 +2047,4 @@ double LIB_SYMBOL::Similarity( const LIB_SYMBOL& aOther ) const
similarity *= 0.9;
return similarity;
}
}

View File

@ -142,7 +142,7 @@ public:
*
* @return the weak_ptr to the root symbol of this symbol.
*/
LIB_SYMBOL_REF GetRootSymbol() const;
LIB_SYMBOL_SPTR GetRootSymbol() const;
void ClearCaches();

View File

@ -436,7 +436,7 @@ void RESCUE_SYMBOL_LIB_TABLE_CANDIDATE::FindRescues(
// If it's a derive symbol, use the parent symbol to perform the pin test.
if( lib_match && lib_match->IsAlias() )
{
lib_match_parent = lib_match->GetRootSymbol().lock();
lib_match_parent = lib_match->GetRootSymbol();
if( !lib_match_parent )
lib_match = nullptr;

View File

@ -160,7 +160,7 @@ void SCH_VIEW::DisplaySymbol( LIB_SYMBOL* aSymbol )
// Draw the parent items if the symbol is inherited from another symbol.
if( aSymbol->IsAlias() )
{
if( std::shared_ptr< LIB_SYMBOL > parent = aSymbol->GetRootSymbol().lock() )
if( std::shared_ptr< LIB_SYMBOL > parent = aSymbol->GetRootSymbol() )
drawnSymbol = parent.get();
else
{

View File

@ -829,7 +829,7 @@ void SYMBOL_EDIT_FRAME::SetCurSymbol( LIB_SYMBOL* aSymbol, bool aUpdateZoom )
wxString rootSymbolName;
// Don't assume the parent symbol shared pointer is still valid.
if( std::shared_ptr<LIB_SYMBOL> rootSymbol = m_symbol->GetRootSymbol().lock() )
if( std::shared_ptr<LIB_SYMBOL> rootSymbol = m_symbol->GetRootSymbol() )
rootSymbolName = rootSymbol->GetName();
else
{

View File

@ -607,9 +607,9 @@ BOOST_AUTO_TEST_CASE( Inheritance )
BOOST_CHECK( grandChild->IsAlias() );
BOOST_CHECK_EQUAL( grandChild->GetInheritanceDepth(), 2 );
BOOST_CHECK( parent->GetRootSymbol().lock().get() == parent.get() );
BOOST_CHECK( child->GetRootSymbol().lock().get() == parent.get() );
BOOST_CHECK( grandChild->GetRootSymbol().lock().get() == parent.get() );
BOOST_CHECK( parent->GetRootSymbol().get() == parent.get() );
BOOST_CHECK( child->GetRootSymbol().get() == parent.get() );
BOOST_CHECK( grandChild->GetRootSymbol().get() == parent.get() );
LIB_SYMBOL_SPTR parentRef = child->GetParent().lock();
BOOST_CHECK( parentRef );