← Back to team overview

kicad-developers team mailing list archive

New fix for bug 1663173

 

Hi all,

Since some recent modifications (I don't search from what version
exactly), bug 1663173 is coming back...

See original description : https://bugs.launchpad.net/kicad/+bug/1663173

Please find attached the patch to fix it.

Following this issue I have two comments:

- For any usage of "poly->Point( 0 )" or anything like, this should be
preceded by a check if value "0" is a valid value.
 Like this:
                if( poly->PointCount() > 0)
                {
                   // Use of poly->Point( 0 )

Same with Outline :
            if( outline.OutlineCount() > 0) {
                // Use of outline.Outline( 0 );
Or any other way to ensure the index X (with X=0 in thoses case) is a
valid index...

- Is it really logic to allow negative clearance in pads ? Should not be
an absolute value ? In this case, interface should avoid this case...

Regards,
From 2b0607ef915a3734f87c5c3b5159cb4340ff4e9c Mon Sep 17 00:00:00 2001
From: Jean-Samuel Reynaud <js.reynaud@xxxxxxxxx>
Date: Wed, 18 Oct 2017 14:41:52 +0200
Subject: [PATCH] Fix crash with clearance is "too" negative. Same bug as
 #1663173
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.7.4"

This is a multi-part message in MIME format.
--------------2.7.4
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


Fixes: lp:1663173
* https://bugs.launchpad.net/kicad/+bug/1663173
---
 pcbnew/class_pad_draw_functions.cpp | 50 +++++++++++++++++++++++++------------
 1 file changed, 34 insertions(+), 16 deletions(-)


--------------2.7.4
Content-Type: text/x-patch; name="0001-Fix-crash-with-clearance-is-too-negative.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-Fix-crash-with-clearance-is-too-negative.patch"

diff --git a/pcbnew/class_pad_draw_functions.cpp b/pcbnew/class_pad_draw_functions.cpp
index 9d270b0..a3884c6 100644
--- a/pcbnew/class_pad_draw_functions.cpp
+++ b/pcbnew/class_pad_draw_functions.cpp
@@ -402,11 +402,16 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
             TransformShapeWithClearanceToPolygon( outline, aDrawInfo.m_PadClearance, SEGCOUNT, 1.0 );
 
             // Draw the polygon: Inflate creates only one convex polygon
-            SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
+            if( outline.OutlineCount() > 0) {
+                SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
 
-            GRClosedPoly( aClipBox, aDC, poly.PointCount(),
-                          (wxPoint*)&poly.Point( 0 ), false, 0,
-                          aDrawInfo.m_Color, aDrawInfo.m_Color );
+                if( poly.PointCount() > 0)
+                {
+                    GRClosedPoly( aClipBox, aDC, poly.PointCount(),
+                                  (wxPoint*)&poly.Point( 0 ), false, 0,
+                                  aDrawInfo.m_Color, aDrawInfo.m_Color );
+                }
+            }
         }
         break;
 
@@ -434,11 +439,16 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
             TransformRoundRectToPolygon( outline, shape_pos, size, GetOrientation(),
                                          corner_radius, 64 );
 
-            SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
+            if( outline.OutlineCount() > 0) {
+                SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
 
-            GRClosedPoly( aClipBox, aDC, poly.PointCount(),
-                          (wxPoint*)&poly.Point( 0 ), aDrawInfo.m_ShowPadFilled, 0,
-                          aDrawInfo.m_Color, aDrawInfo.m_Color );
+                if( poly.PointCount() > 0)
+                {
+                    GRClosedPoly( aClipBox, aDC, poly.PointCount(),
+                                  (wxPoint*)&poly.Point( 0 ), aDrawInfo.m_ShowPadFilled, 0,
+                                  aDrawInfo.m_Color, aDrawInfo.m_Color );
+                }
+            }
         }
 
         if( aDrawInfo.m_PadClearance )
@@ -452,12 +462,17 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
             TransformRoundRectToPolygon( outline, shape_pos, size, GetOrientation(),
                                      corner_radius, 32 );
 
-            // Draw the polygon: Inflate creates only one convex polygon
-            SHAPE_LINE_CHAIN& clearance_poly = outline.Outline( 0 );
+            if( outline.OutlineCount() > 0) {
+                // Draw the polygon: Inflate creates only one convex polygon
+                SHAPE_LINE_CHAIN& clearance_poly = outline.Outline( 0 );
 
-            GRClosedPoly( aClipBox, aDC, clearance_poly.PointCount(),
-                          (wxPoint*)&clearance_poly.Point( 0 ), false, 0,
-                          aDrawInfo.m_Color, aDrawInfo.m_Color );
+                if( clearance_poly.PointCount() > 0)
+                {
+                    GRClosedPoly( aClipBox, aDC, clearance_poly.PointCount(),
+                                  (wxPoint*)&clearance_poly.Point( 0 ), false, 0,
+                                  aDrawInfo.m_Color, aDrawInfo.m_Color );
+                }
+            }
         }
     }
         break;
@@ -541,9 +556,12 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
             {
                 poly = &clearance_outline.Outline( jj );
 
-                GRClosedPoly( aClipBox, aDC, poly->PointCount(),
-                              (wxPoint*)&poly->Point( 0 ), false, 0,
-                              aDrawInfo.m_Color, aDrawInfo.m_Color );
+                if( poly->PointCount() > 0)
+                {
+                    GRClosedPoly( aClipBox, aDC, poly->PointCount(),
+                                  (wxPoint*)&poly->Point( 0 ), false, 0,
+                                  aDrawInfo.m_Color, aDrawInfo.m_Color );
+                }
             }
         }
         break;

--------------2.7.4--



Follow ups