From b327da6e5a4a96295b5b3db40d3cb1505b63cda1 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 15 Jan 2018 10:53:25 +0100 Subject: [PATCH] Fix incorrect parsing in kicad2step when a footprint has both locked and placed options activated. Fixes: lp:1742700 https://bugs.launchpad.net/kicad/+bug/1742700 --- utils/kicad2step/pcb/kicadmodule.cpp | 32 +++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/utils/kicad2step/pcb/kicadmodule.cpp b/utils/kicad2step/pcb/kicadmodule.cpp index 0b3807bb4d..ef5a39a25f 100644 --- a/utils/kicad2step/pcb/kicadmodule.cpp +++ b/utils/kicad2step/pcb/kicadmodule.cpp @@ -2,6 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2016 Cirilo Bernardo + * Copyright 2018 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -85,22 +86,33 @@ bool KICADMODULE::Read( SEXPR::SEXPR* aEntry ) for( size_t i = 2; i < nc && result; ++i ) { child = aEntry->GetChild( i ); + std::string symname; - // skip the optional 'locked' attribute; due to the vagaries of the + // skip the optional locked and/or placed attributes; due to the vagaries of the // kicad version of sexpr, the attribute may be a Symbol or a String - if( i <= 2 && ( child->IsSymbol() || child->IsString() ) ) - continue; - - if( !child->IsList() ) + if( child->IsSymbol() || child->IsString() ) { - std::ostringstream ostr; - ostr << "* corrupt module in PCB file at line "; - ostr << child->GetLineNumber() << "\n"; - wxLogMessage( "%s\n", ostr.str().c_str() ); + if( child->IsSymbol() ) + symname = child->GetSymbol(); + else if( child->IsString() ) + symname = child->GetString(); + + if( symname == "locked" || symname == "placed" ) + continue; + + wxLogMessage( "* module descr in PCB file at line %d: unexpected keyword '%s'\n", + child->GetLineNumber(), symname.c_str() ); return false; } - std::string symname( child->GetChild( 0 )->GetSymbol() ); + if( !child->IsList() ) + { + wxLogMessage( "* corrupt module in PCB file at line %d\n", + child->GetLineNumber() ); + return false; + } + + symname = child->GetChild( 0 )->GetSymbol(); if( symname == "layer" ) result = result && parseLayer( child );