From 90eed8b4b6de3fc97645f132f97dcb8e10bdc06f Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Wed, 20 Mar 2024 18:34:18 +0100 Subject: [PATCH] Avoid using a nullptr. --- pcbnew/router/pns_kicad_iface.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index f67a62de53..ad09f646aa 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -1891,8 +1891,11 @@ void PNS_KICAD_IFACE_BASE::AddItem( PNS::ITEM* aItem ) BOARD_CONNECTED_ITEM* PNS_KICAD_IFACE::createBoardItem( PNS::ITEM* aItem ) { - BOARD_CONNECTED_ITEM* newBI = nullptr; - auto net = static_cast( aItem->Net() ); + BOARD_CONNECTED_ITEM* newBoardItem = nullptr; + NETINFO_ITEM* net = static_cast( aItem->Net() ); + + if( !net ) + net = NETINFO_LIST::OrphanedItem(); switch( aItem->Kind() ) { @@ -1903,7 +1906,7 @@ BOARD_CONNECTED_ITEM* PNS_KICAD_IFACE::createBoardItem( PNS::ITEM* aItem ) new_arc->SetWidth( arc->Width() ); new_arc->SetLayer( ToLAYER_ID( arc->Layers().Start() ) ); new_arc->SetNet( net ); - newBI = new_arc; + newBoardItem = new_arc; break; } @@ -1917,7 +1920,7 @@ BOARD_CONNECTED_ITEM* PNS_KICAD_IFACE::createBoardItem( PNS::ITEM* aItem ) track->SetWidth( seg->Width() ); track->SetLayer( ToLAYER_ID( seg->Layers().Start() ) ); track->SetNet( net ); - newBI = track; + newBoardItem = track; break; } @@ -1933,7 +1936,7 @@ BOARD_CONNECTED_ITEM* PNS_KICAD_IFACE::createBoardItem( PNS::ITEM* aItem ) via_board->SetIsFree( via->IsFree() ); via_board->SetLayerPair( ToLAYER_ID( via->Layers().Start() ), ToLAYER_ID( via->Layers().End() ) ); - newBI = via_board; + newBoardItem = via_board; break; } @@ -1952,12 +1955,13 @@ BOARD_CONNECTED_ITEM* PNS_KICAD_IFACE::createBoardItem( PNS::ITEM* aItem ) if( net->GetNetCode() <= 0 ) { - NETINFO_ITEM* newNetInfo = newBI->GetNet(); + NETINFO_ITEM* newNetInfo = newBoardItem->GetNet(); + newNetInfo->SetParent( m_board ); newNetInfo->SetNetClass( m_board->GetDesignSettings().m_NetSettings->m_DefaultNetClass ); } - return newBI; + return newBoardItem; }