Commit 2af3e5f6 authored by Maciej Suminski's avatar Maciej Suminski

bugfix #1325743: cvpcb crashes when opening any netlist.

parent 563502b8
......@@ -1305,13 +1305,13 @@ void LEGACY_PLUGIN::loadPAD( MODULE* aModule )
int netcode = intParse( line + SZ( "Ne" ), &data );
// Store the new code mapping
pad->SetNetCode( m_netCodes[netcode] );
pad->SetNetCode( getNetCode( netcode ) );
// read Netname
ReadDelimitedText( buf, data, sizeof(buf) );
#ifndef NDEBUG
if( m_board )
assert( m_board->FindNet( m_netCodes[netcode] )->GetNetname() ==
assert( m_board->FindNet( getNetCode( netcode ) )->GetNetname() ==
FROM_UTF8( StrPurge( buf ) ) );
#endif /* NDEBUG */
}
......@@ -2102,7 +2102,7 @@ void LEGACY_PLUGIN::loadTrackList( int aStructType )
via->SetLayerPair( LAYER_N_FRONT, LAYER_N_BACK );
}
newTrack->SetNetCode( m_netCodes[net_code] );
newTrack->SetNetCode( getNetCode( net_code ) );
newTrack->SetState( flags, true );
m_board->Add( newTrack );
......@@ -2250,7 +2250,7 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER()
// Init the net code only, not the netname, to be sure
// the zone net name is the name read in file.
// (When mismatch, the user will be prompted in DRC, to fix the actual name)
zc->BOARD_CONNECTED_ITEM::SetNetCode( m_netCodes[netcode] );
zc->BOARD_CONNECTED_ITEM::SetNetCode( getNetCode( netcode ) );
}
else if( TESTLINE( "ZLayer" ) ) // layer found
......
......@@ -139,6 +139,16 @@ protected:
double diskToBiu; ///< convert from disk engineering units to BIUs
///< with this scale factor
///> Converts net code using the mapping table if available,
///> otherwise returns unchanged net code
inline int getNetCode( int aNetCode )
{
if( aNetCode < (int) m_netCodes.size() )
return m_netCodes[aNetCode];
return aNetCode;
}
/**
* Function biuParse
* parses an ASCII decimal floating point value and scales it into a BIU
......
......@@ -2201,7 +2201,7 @@ D_PAD* PCB_PARSER::parseD_PAD( MODULE* aParent ) throw( IO_ERROR, PARSE_ERROR )
break;
case T_net:
pad->SetNetCode( m_netCodes[parseInt( "net number" )] );
pad->SetNetCode( getNetCode( parseInt( "net number" ) ) );
NeedSYMBOLorNUMBER();
assert( FromUTF8() == m_board->FindNet( pad->GetNetCode() )->GetNetname() );
NeedRIGHT();
......@@ -2299,7 +2299,7 @@ TRACK* PCB_PARSER::parseTRACK() throw( IO_ERROR, PARSE_ERROR )
break;
case T_net:
track->SetNetCode( m_netCodes[parseInt( "net number" )] );
track->SetNetCode( getNetCode( parseInt( "net number" ) ) );
break;
case T_tstamp:
......@@ -2377,7 +2377,7 @@ VIA* PCB_PARSER::parseVIA() throw( IO_ERROR, PARSE_ERROR )
break;
case T_net:
via->SetNetCode( m_netCodes[parseInt( "net number" )] );
via->SetNetCode( getNetCode( parseInt( "net number" ) ) );
NeedRIGHT();
break;
......@@ -2429,7 +2429,7 @@ ZONE_CONTAINER* PCB_PARSER::parseZONE_CONTAINER() throw( IO_ERROR, PARSE_ERROR )
// Init the net code only, not the netname, to be sure
// the zone net name is the name read in file.
// (When mismatch, the user will be prompted in DRC, to fix the actual name)
zone->SetNetCode( m_netCodes[parseInt( "net number" )] );
zone->SetNetCode( getNetCode( parseInt( "net number" ) ) );
NeedRIGHT();
break;
......
......@@ -69,6 +69,16 @@ class PCB_PARSER : public PCB_LEXER
LAYER_MSK_MAP m_layerMasks; ///< map layer names to their masks
std::vector<int> m_netCodes; ///< net codes mapping for boards being loaded
///> Converts net code using the mapping table if available,
///> otherwise returns unchanged net code
inline int getNetCode( int aNetCode )
{
if( aNetCode < (int) m_netCodes.size() )
return m_netCodes[aNetCode];
return aNetCode;
}
/**
* Function init
* clears and re-establishes m_layerMap with the default layer names.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment