Fix crash when parsing a PCB file with an invalid net code.

This commit is contained in:
Chris Pavlina 2015-06-08 15:28:04 -04:00 committed by Wayne Stambaugh
parent 859435cabe
commit 097c73b8eb
3 changed files with 12 additions and 4 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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: