pcbnew: Prevent use of non-connected item in ratsnest

We need to be careful in the connectivity system to always use
dyn_cast/dynamic_cast and check the return when dealing with board
items.  Getting non-connected items will result in null nets when
propagated.

Fixes https://gitlab.com/kicad/code/kicad/issues/5082

(cherry picked from commit 406de56964)
This commit is contained in:
Seth Hillbrand 2020-08-07 13:37:00 -07:00
parent 5ef9db6d67
commit 9bc3028eb7
2 changed files with 17 additions and 11 deletions

View File

@ -39,6 +39,11 @@
bool CN_CONNECTIVITY_ALGO::Remove( BOARD_ITEM* aItem )
{
BOARD_CONNECTED_ITEM* citem = dyn_cast<BOARD_CONNECTED_ITEM*>( aItem );
if( !citem )
return false;
markItemNetAsDirty( aItem );
switch( aItem->Type() )
@ -46,35 +51,35 @@ bool CN_CONNECTIVITY_ALGO::Remove( BOARD_ITEM* aItem )
case PCB_MODULE_T:
for( auto pad : static_cast<MODULE*>( aItem ) -> Pads() )
{
m_itemMap[ static_cast<BOARD_CONNECTED_ITEM*>( pad ) ].MarkItemsAsInvalid();
m_itemMap.erase( static_cast<BOARD_CONNECTED_ITEM*>( pad ) );
m_itemMap[pad].MarkItemsAsInvalid();
m_itemMap.erase( pad );
}
m_itemList.SetDirty( true );
break;
case PCB_PAD_T:
m_itemMap[ static_cast<BOARD_CONNECTED_ITEM*>( aItem ) ].MarkItemsAsInvalid();
m_itemMap.erase( static_cast<BOARD_CONNECTED_ITEM*>( aItem ) );
m_itemMap[citem].MarkItemsAsInvalid();
m_itemMap.erase( citem );
m_itemList.SetDirty( true );
break;
case PCB_TRACE_T:
m_itemMap[ static_cast<BOARD_CONNECTED_ITEM*>( aItem ) ].MarkItemsAsInvalid();
m_itemMap.erase( static_cast<BOARD_CONNECTED_ITEM*>( aItem ) );
m_itemMap[citem].MarkItemsAsInvalid();
m_itemMap.erase( citem );
m_itemList.SetDirty( true );
break;
case PCB_VIA_T:
m_itemMap[ static_cast<BOARD_CONNECTED_ITEM*>( aItem ) ].MarkItemsAsInvalid();
m_itemMap.erase( static_cast<BOARD_CONNECTED_ITEM*>( aItem ) );
m_itemMap[citem].MarkItemsAsInvalid();
m_itemMap.erase( citem );
m_itemList.SetDirty( true );
break;
case PCB_ZONE_AREA_T:
{
m_itemMap[ static_cast<BOARD_CONNECTED_ITEM*>( aItem ) ].MarkItemsAsInvalid();
m_itemMap.erase ( static_cast<BOARD_CONNECTED_ITEM*>( aItem ) );
m_itemMap[citem].MarkItemsAsInvalid();
m_itemMap.erase ( citem );
m_itemList.SetDirty( true );
break;
}

View File

@ -206,7 +206,8 @@ void CONNECTIVITY_DATA::BlockRatsnestItems( const std::vector<BOARD_ITEM*>& aIte
}
else
{
citems.push_back( static_cast<BOARD_CONNECTED_ITEM*>(item) );
if( auto citem = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
citems.push_back( citem );
}
}