From 097c73b8eb1f9e59290c95be2992e8494a63a4e4 Mon Sep 17 00:00:00 2001 From: Chris Pavlina Date: Mon, 8 Jun 2015 15:28:04 -0400 Subject: [PATCH] Fix crash when parsing a PCB file with an invalid net code. --- pcbnew/class_board_connected_item.cpp | 6 ++++-- pcbnew/class_board_connected_item.h | 4 +++- pcbnew/pcb_parser.cpp | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pcbnew/class_board_connected_item.cpp b/pcbnew/class_board_connected_item.cpp index 797e2ee158..82a2153190 100644 --- a/pcbnew/class_board_connected_item.cpp +++ b/pcbnew/class_board_connected_item.cpp @@ -48,7 +48,7 @@ BOARD_CONNECTED_ITEM::BOARD_CONNECTED_ITEM( const BOARD_CONNECTED_ITEM& aItem ) } -void BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode ) +bool BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode, bool aNoAssert ) { // if aNetCode < 0 ( typically NETINFO_LIST::FORCE_ORPHANED ) // or no parent board, @@ -61,7 +61,9 @@ void BOARD_CONNECTED_ITEM::SetNetCode( int aNetCode ) else m_netinfo = &NETINFO_LIST::ORPHANED; - assert( m_netinfo ); + if( !aNoAssert ) + assert( m_netinfo ); + return m_netinfo; } diff --git a/pcbnew/class_board_connected_item.h b/pcbnew/class_board_connected_item.h index 15dfe31f54..fea45544e7 100644 --- a/pcbnew/class_board_connected_item.h +++ b/pcbnew/class_board_connected_item.h @@ -104,9 +104,11 @@ public: * Function SetNetCode * sets net using a net code. * @param aNetCode is a net code for the new net. It has to exist in NETINFO_LIST held by BOARD. + * @param aNoAssert if true, do not assert that the net exists. * Otherwise, item is assigned to the unconnected net. + * @return true on success, false if the net did not exist */ - void SetNetCode( int aNetCode ); + bool SetNetCode( int aNetCode, bool aNoAssert=false ); /** * Function GetSubNet diff --git a/pcbnew/pcb_parser.cpp b/pcbnew/pcb_parser.cpp index c9a2e427fb..500e0c0d94 100644 --- a/pcbnew/pcb_parser.cpp +++ b/pcbnew/pcb_parser.cpp @@ -2408,7 +2408,11 @@ TRACK* PCB_PARSER::parseTRACK() throw( IO_ERROR, PARSE_ERROR ) break; case T_net: - track->SetNetCode( getNetCode( parseInt( "net number" ) ) ); + if( ! track->SetNetCode( getNetCode( parseInt( "net number" ) ), /* aNoAssert */ true ) ) + THROW_IO_ERROR( + wxString::Format( _( "invalid net ID in\nfile: <%s>\nline: %d\noffset: %d" ), + GetChars( CurSource() ), CurLineNumber(), CurOffset() ) + ); break; case T_tstamp: