From bc77a1e2ddbef3b2c083b5009f151a9cdf16933c Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 14 Jan 2022 18:17:14 +0100 Subject: [PATCH] drc_test_provider_library_parity: fix a crash due to a incorrect if()...else() logic. The incorrect logic allowed execution of the else sequence when it should not be executed. --- .../drc/drc_test_provider_library_parity.cpp | 76 +++++++++++-------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/pcbnew/drc/drc_test_provider_library_parity.cpp b/pcbnew/drc/drc_test_provider_library_parity.cpp index ec2c8537e1..510bb1e01f 100644 --- a/pcbnew/drc/drc_test_provider_library_parity.cpp +++ b/pcbnew/drc/drc_test_provider_library_parity.cpp @@ -322,6 +322,8 @@ bool modelsNeedUpdate( const FP_3DMODEL& a, const FP_3DMODEL& b ) bool FOOTPRINT::FootprintNeedsUpdate( const FOOTPRINT* aLibFootprint ) { + wxASSERT( aLibFootprint ); + if( IsFlipped() ) { std::unique_ptr temp( static_cast( Clone() ) ); @@ -444,26 +446,31 @@ bool DRC_TEST_PROVIDER_LIBRARY_PARITY::Run() { } - if( !libTableRow && !m_drcEngine->IsErrorLimitExceeded( DRCE_LIB_FOOTPRINT_ISSUES ) ) + if( !libTableRow ) { - std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_LIB_FOOTPRINT_ISSUES ); - msg.Printf( _( "The current configuration does not include the library '%s'." ), - libName ); - drcItem->SetErrorMessage( msg ); - drcItem->SetItems( footprint ); - reportViolation( drcItem, footprint->GetCenter(), UNDEFINED_LAYER ); + if( !m_drcEngine->IsErrorLimitExceeded( DRCE_LIB_FOOTPRINT_ISSUES ) ) + { + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_LIB_FOOTPRINT_ISSUES ); + msg.Printf( _( "The current configuration does not include the library '%s'." ), + libName ); + drcItem->SetErrorMessage( msg ); + drcItem->SetItems( footprint ); + reportViolation( drcItem, footprint->GetCenter(), UNDEFINED_LAYER ); + } continue; } - else if( !libTable->HasLibrary( libName, true ) - && !m_drcEngine->IsErrorLimitExceeded( DRCE_LIB_FOOTPRINT_ISSUES )) + else if( !libTable->HasLibrary( libName, true ) ) { - std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_LIB_FOOTPRINT_ISSUES ); - msg.Printf( _( "The library '%s' is not enabled in the current configuration." ), - libName ); - drcItem->SetErrorMessage( msg ); - drcItem->SetItems( footprint ); - reportViolation( drcItem, footprint->GetCenter(), UNDEFINED_LAYER ); + if( !m_drcEngine->IsErrorLimitExceeded( DRCE_LIB_FOOTPRINT_ISSUES ) ) + { + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_LIB_FOOTPRINT_ISSUES ); + msg.Printf( _( "The library '%s' is not enabled in the current configuration." ), + libName ); + drcItem->SetErrorMessage( msg ); + drcItem->SetItems( footprint ); + reportViolation( drcItem, footprint->GetCenter(), UNDEFINED_LAYER ); + } continue; } @@ -489,26 +496,31 @@ bool DRC_TEST_PROVIDER_LIBRARY_PARITY::Run() } } - if( !libFootprint && !m_drcEngine->IsErrorLimitExceeded( DRCE_LIB_FOOTPRINT_ISSUES ) ) + if( !libFootprint ) { - std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_LIB_FOOTPRINT_ISSUES ); - msg.Printf( "Footprint '%s' not found in library '%s'.", - fpName, - libName ); - drcItem->SetErrorMessage( msg ); - drcItem->SetItems( footprint ); - reportViolation( drcItem, footprint->GetCenter(), UNDEFINED_LAYER ); + if( !m_drcEngine->IsErrorLimitExceeded( DRCE_LIB_FOOTPRINT_ISSUES ) ) + { + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_LIB_FOOTPRINT_ISSUES ); + msg.Printf( "Footprint '%s' not found in library '%s'.", + fpName, + libName ); + drcItem->SetErrorMessage( msg ); + drcItem->SetItems( footprint ); + reportViolation( drcItem, footprint->GetCenter(), UNDEFINED_LAYER ); + } } - else if( footprint->FootprintNeedsUpdate( libFootprint.get() ) - && !m_drcEngine->IsErrorLimitExceeded( DRCE_LIB_FOOTPRINT_MISMATCH )) + else if( footprint->FootprintNeedsUpdate( libFootprint.get() ) ) { - std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_LIB_FOOTPRINT_MISMATCH ); - msg.Printf( "Footprint '%s' does not match copy in library '%s'.", - fpName, - libName ); - drcItem->SetErrorMessage( msg ); - drcItem->SetItems( footprint ); - reportViolation( drcItem, footprint->GetCenter(), UNDEFINED_LAYER ); + if( !m_drcEngine->IsErrorLimitExceeded( DRCE_LIB_FOOTPRINT_MISMATCH ) ) + { + std::shared_ptr drcItem = DRC_ITEM::Create( DRCE_LIB_FOOTPRINT_MISMATCH ); + msg.Printf( "Footprint '%s' does not match copy in library '%s'.", + fpName, + libName ); + drcItem->SetErrorMessage( msg ); + drcItem->SetItems( footprint ); + reportViolation( drcItem, footprint->GetCenter(), UNDEFINED_LAYER ); + } } }