← Back to team overview

kicad-developers team mailing list archive

[PATCH] Prevent segfault when aOutline has no vertices.

 

When attempting to read a pcad file exported from Altium, kicad was segfaulting because it was trying to access an empty array. This patch fixes that.

The reason the array was empty was the the board outline in the pcad file was composed of only arcs and the plugin only processes lines in the board outline. Adding this functionality is for another patch I suppose.

-hauptmech

---
 pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp
index 6d7045fb9..664742056 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp
@@ -94,8 +94,10 @@ void PCB_POLYGON::SetOutline( VERTICES_ARRAY* aOutline )
     for( i = 0; i < (int) aOutline->GetCount(); i++ )
m_outline.Add( new wxRealPoint( (*aOutline)[i]->x, (*aOutline)[i]->y ) );

-    m_positionX = m_outline[0]->x;
-    m_positionY = m_outline[0]->y;
+   if (m_outline.Count() > 0){
+       m_positionX = m_outline[0]->x;
+       m_positionY = m_outline[0]->y;
+   }
 }

 void PCB_POLYGON::FormPolygon( XNODE*   aNode, VERTICES_ARRAY* aPolygon,
--
2.11.1



Follow ups