Eeschema: fix a crash that sometimes happens with bus entries,

connected to the same point on a bus.
The pointers used in previous code could be null, but they were not tested.
The pointer validity is now tested.
This commit is contained in:
jean-pierre charras 2019-12-22 16:19:05 +01:00
parent 18ff60fbb9
commit 7b80b2dc7b
3 changed files with 21 additions and 13 deletions

View File

@ -2015,21 +2015,27 @@ bool CONNECTION_GRAPH::ercCheckBusToBusEntryConflicts( const CONNECTION_SUBGRAPH
if( bus_entry && bus_entry->m_connected_bus_item )
{
bus_wire = bus_entry->m_connected_bus_item;
conflict = true;
auto test_name = bus_entry->Connection( sheet )->Name( true );
for( const auto& member : bus_wire->Connection( sheet )->Members() )
// In some cases, the connection list (SCH_CONNECTION*) can be null.
// Skip null connections.
if( bus_entry->Connection( sheet ) && bus_wire->Connection( sheet ) )
{
if( member->Type() == CONNECTION_BUS )
conflict = true;
auto test_name = bus_entry->Connection( sheet )->Name( true );
for( const auto& member : bus_wire->Connection( sheet )->Members() )
{
for( const auto& sub_member : member->Members() )
if( sub_member->Name( true ) == test_name )
conflict = false;
}
else if( member->Name( true ) == test_name )
{
conflict = false;
if( member->Type() == CONNECTION_BUS )
{
for( const auto& sub_member : member->Members() )
if( sub_member->Name( true ) == test_name )
conflict = false;
}
else if( member->Name( true ) == test_name )
{
conflict = false;
}
}
}
}

View File

@ -127,7 +127,8 @@ bool SCH_ITEM::IsConnected( const wxPoint& aPosition ) const
SCH_CONNECTION* SCH_ITEM::Connection( const SCH_SHEET_PATH& aSheet ) const
{
if( m_connection_map.count( aSheet ) )
// Warning: the m_connection_map can be empty.
if( m_connection_map.size() && m_connection_map.count( aSheet ) )
return m_connection_map.at( aSheet );
return nullptr;

View File

@ -327,6 +327,7 @@ public:
/**
* Retrieves the connection associated with this object in the given sheet
* Note: the returned value can be nullptr.
*/
SCH_CONNECTION* Connection( const SCH_SHEET_PATH& aPath ) const;