Eagle: Fix crash when importing Eagle V6

This fixes multiple issues when importing Eagle V6 files.

Crashes occured when arcs of 0-length were found and when parts were
referenced in the schematic that were not found in the library.  This
could happen if the library and schematic were different cases.

Fixes: lp:1830564
* https://bugs.launchpad.net/kicad/+bug/1830564

(cherry picked from commit 0e5cc54ec9)
This commit is contained in:
Seth Hillbrand 2019-05-26 20:12:27 -07:00
parent cb3edf2607
commit b4e70e56a6
3 changed files with 31 additions and 7 deletions

View File

@ -109,7 +109,9 @@ long long int ECOORD::ConvertToNm( int aValue, enum EAGLE_UNIT aUnit )
case EU_MIL: ret = (long long) aValue * 25400; break;
}
wxASSERT( ( ret > 0 ) == ( aValue > 0 ) ); // check for overflow
if( ( ret > 0 ) != ( aValue > 0 ) )
wxLogError( _( "Invalid size %lld: too large" ), aValue );
return ret;
}
@ -283,8 +285,13 @@ wxPoint ConvertArcCenter( const wxPoint& aStart, const wxPoint& aEnd, double aAn
wxPoint mid = ( aStart + aEnd ) / 2;
double dlen = sqrt( dx*dx + dy*dy );
wxASSERT( dlen != 0 );
wxASSERT( aAngle != 0 );
if( !std::isnormal( dlen ) || !std::isnormal( aAngle ) )
{
THROW_IO_ERROR(
wxString::Format( _( "Invalid Arc with radius %f and angle %f" ), dlen, aAngle ) );
}
double dist = dlen / ( 2 * tan( DEG2RAD( aAngle ) / 2 ) );
wxPoint center(
@ -608,7 +615,7 @@ wxSize ETEXT::ConvertSize() const
}
else
{
wxASSERT( false );
wxLogDebug( "Invalid font name \"%s\"", fontName );
textsize = wxSize( size.ToSchUnits(), size.ToSchUnits() );
}
}

View File

@ -626,7 +626,8 @@ void LIB_PART::RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel, wxDC* aD
void LIB_PART::AddDrawItem( LIB_ITEM* aItem )
{
wxASSERT( aItem != NULL );
if( !aItem )
return;
m_drawings.push_back( aItem );
}

View File

@ -533,7 +533,9 @@ void SCH_EAGLE_PLUGIN::loadSchematic( wxXmlNode* aSchematicNode )
while( partNode )
{
std::unique_ptr<EPART> epart( new EPART( partNode ) );
m_partlist[epart->name] = std::move( epart );
// N.B. Eagle parts are case-insensitive in matching but we keep the display case
m_partlist[epart->name.Upper()] = std::move( epart );
partNode = partNode->GetNext();
}
@ -1061,7 +1063,18 @@ void SCH_EAGLE_PLUGIN::loadInstance( wxXmlNode* aInstanceNode )
// Calculate the unit number from the gate entry of the instance
// Assign the the LIB_ID from deviceset and device names
EPART* epart = m_partlist[einstance.part].get();
auto part_it = m_partlist.find( einstance.part.Upper() );
if( part_it == m_partlist.end() )
{
wxLogError( _( "Error parsing Eagle file. "
"Could not find \"%s\" instance but it is referenced in the schematic." ),
einstance.part );
return;
}
EPART* epart = part_it->second.get();
wxString libraryname = epart->library;
wxString gatename = epart->deviceset + epart->device + einstance.gate;
@ -1566,6 +1579,9 @@ LIB_ITEM* SCH_EAGLE_PLUGIN::loadSymbolWire( std::unique_ptr<LIB_PART>& aPart,
end.x = ewire.x2.ToSchUnits();
end.y = ewire.y2.ToSchUnits();
if( begin == end )
return nullptr;
// if the wire is an arc
if( ewire.curve )
{