Fix crash in symbol editor when importing Eagle symbol library.

https://gitlab.com/kicad/code/kicad/-/issues/18221
This commit is contained in:
Wayne Stambaugh 2024-06-21 01:07:01 -04:00
parent 3df2109c43
commit 8df28d4f5f
2 changed files with 30 additions and 7 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com> * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2012-2023 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2012-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2017 CERN. * Copyright (C) 2017 CERN.
* *
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com> * @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
@ -1461,7 +1461,7 @@ ELAYER::ELAYER( wxXmlNode* aLayer, IO_BASE* aIo ) :
number = parseRequiredAttribute<int>( aLayer, "number" ); number = parseRequiredAttribute<int>( aLayer, "number" );
name = parseRequiredAttribute<wxString>( aLayer, "name" ); name = parseRequiredAttribute<wxString>( aLayer, "name" );
color = parseRequiredAttribute<int>( aLayer, "color" ); color = parseRequiredAttribute<int>( aLayer, "color" );
fill = 1; // Temporary value. fill = parseRequiredAttribute<int>( aLayer, "fill" );
visible = parseOptionalAttribute<bool>( aLayer, "visible" ); visible = parseOptionalAttribute<bool>( aLayer, "visible" );
active = parseOptionalAttribute<bool>( aLayer, "active" ); active = parseOptionalAttribute<bool>( aLayer, "active" );
@ -2424,8 +2424,18 @@ ELIBRARY::ELIBRARY( wxXmlNode* aLibrary, IO_BASE* aIo ) :
* <!-- name: Only in libraries used inside boards or schematics --> * <!-- name: Only in libraries used inside boards or schematics -->
* <!-- urn: Only in online libraries used inside boards or schematics --> * <!-- urn: Only in online libraries used inside boards or schematics -->
*/ */
name = parseRequiredAttribute<wxString>( aLibrary, "name" );
urn = parseOptionalAttribute<wxString>( aLibrary, "urn" ); // The name and urn attributes are only valid in schematic and board files.
wxString parentNodeName;
if( aLibrary->GetParent() )
parentNodeName = aLibrary->GetParent()->GetName();
if( parentNodeName == "libraries" )
{
name = parseRequiredAttribute<wxString>( aLibrary, "name" );
urn = parseOptionalAttribute<wxString>( aLibrary, "urn" );
}
for( wxXmlNode* child = aLibrary->GetChildren(); child; child = child->GetNext() ) for( wxXmlNode* child = aLibrary->GetChildren(); child; child = child->GetNext() )
{ {
@ -2673,14 +2683,20 @@ EDRAWING::EDRAWING( wxXmlNode* aDrawing, IO_BASE* aIo ) :
else if( child->GetName() == "filters" ) else if( child->GetName() == "filters" )
{ {
for( wxXmlNode* filter = child->GetChildren(); filter; filter = filter->GetNext() ) for( wxXmlNode* filter = child->GetChildren(); filter; filter = filter->GetNext() )
filters.emplace_back( std::make_unique<EFILTER>( filter, aIo ) ); {
if( filter->GetName() == "filter" )
filters.emplace_back( std::make_unique<EFILTER>( filter, aIo ) );
}
AdvanceProgressPhase(); AdvanceProgressPhase();
} }
else if( child->GetName() == "layers" ) else if( child->GetName() == "layers" )
{ {
for( wxXmlNode* layer = child->GetChildren(); layer; layer = layer->GetNext() ) for( wxXmlNode* layer = child->GetChildren(); layer; layer = layer->GetNext() )
layers.emplace_back( std::make_unique<ELAYER>( layer, aIo ) ); {
if( layer->GetName() == "layer" )
layers.emplace_back( std::make_unique<ELAYER>( layer, aIo ) );
}
AdvanceProgressPhase(); AdvanceProgressPhase();
} }

View File

@ -3,7 +3,7 @@
* *
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com> * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
* Copyright (C) 2004-2023 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2004-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -26,6 +26,7 @@
#include <confirm.h> #include <confirm.h>
#include <kidialog.h> #include <kidialog.h>
#include <common.h> #include <common.h>
#include <io/eagle/eagle_parser.h>
#include <symbol_lib_table.h> #include <symbol_lib_table.h>
#include <symbol_edit_frame.h> #include <symbol_edit_frame.h>
#include <symbol_library.h> #include <symbol_library.h>
@ -109,6 +110,12 @@ void SYMBOL_EDIT_FRAME::ImportSymbol()
DisplayErrorMessage( this, msg, ioe.What() ); DisplayErrorMessage( this, msg, ioe.What() );
return; return;
} }
catch( const XML_PARSER_ERROR& ioe )
{
msg.Printf( _( "Cannot import symbol library '%s'." ), fn.GetFullPath() );
DisplayErrorMessage( this, msg, ioe.what() );
return;
}
if( symbols.empty() ) if( symbols.empty() )
{ {