← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Prevent segfault when aOutline has no vertices.

 

Well...

I had a look at this for my very own training pleasure and updated the patch from Hauptmechto to suit the coding style AFAICT.
(attached)

Regards,

Clemens

On 2017-02-13 21:09, hauptmech wrote:
> Thanks for the heads up Chris.
> 
> Respectfully to the developers, I don't have time. If this does not 
> match your coding style then consider it bug report.
> 
> -Hauptmech
> 
> On 14/02/17 04:00, Chris Pavlina wrote:
>> Thank you for your contribution.
>>
>> We're generally pretty strict about the coding style for new code; it
>> can be found at Documentation/development/coding-style-policy.md in the
>> source tree. If you don't see what the problem is, pay particular
>> attention to spacing around parentheses, and to the placement of braces
>> {}. I'd normally just fix this myself on such a small patch, but since
>> Wayne has taken this thread I'll let him wait for you to submit a fixed
>> patch. Just thought I'd explain in a bit more detail.
>>
>> -- Chris
> 
> 
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
> 
>From a9c6bfdb97a7d9841b99a8e84eeb88f17cfe621b Mon Sep 17 00:00:00 2001
From: Clemens Koller <cko@xxxxxxxxx>
Date: Mon, 13 Feb 2017 22:04:53 +0100
Subject: pcbnew: pcad2kicad_plugin: fix segfault when array stays empty.

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

Patch reformatted and

Signed-off-by: Clemens Koller <cko@xxxxxxxxx>

diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp
index 6d7045fb9..833a4bb89 100644
--- a/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp
+++ b/pcbnew/pcad2kicadpcb_plugin/pcb_polygon.cpp
@@ -3,7 +3,7 @@
  *
  * Copyright (C) 2007, 2008 Lubo Racko <developer@xxxxxxx>
  * Copyright (C) 2007, 2008, 2012-2013 Alexander Lunev <al.lunev@xxxxxxxxx>
- * Copyright (C) 2012 KiCad Developers, see CHANGELOG.TXT for contributors.
+ * Copyright (C) 2017 KiCad Developers, see CHANGELOG.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
@@ -94,8 +94,11 @@ 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,

Follow ups

References