From 7b80b2dc7b657cbf6c3a66e4737ab1bf3674708d Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 22 Dec 2019 16:19:05 +0100 Subject: [PATCH] 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. --- eeschema/connection_graph.cpp | 30 ++++++++++++++++++------------ eeschema/sch_item.cpp | 3 ++- eeschema/sch_item.h | 1 + 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/eeschema/connection_graph.cpp b/eeschema/connection_graph.cpp index c1684fc2fc..b75fa7bd3a 100644 --- a/eeschema/connection_graph.cpp +++ b/eeschema/connection_graph.cpp @@ -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; + } } } } diff --git a/eeschema/sch_item.cpp b/eeschema/sch_item.cpp index c1de484665..544bdf3f88 100644 --- a/eeschema/sch_item.cpp +++ b/eeschema/sch_item.cpp @@ -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; diff --git a/eeschema/sch_item.h b/eeschema/sch_item.h index 1810f83953..3cd2edbb93 100644 --- a/eeschema/sch_item.h +++ b/eeschema/sch_item.h @@ -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;