← Back to team overview

kicad-developers team mailing list archive

Segmentation Fault when creating a copper zone

 

Hi,

I've experienced crashes in pcbnew when creating a cooper fill zone when
no board edges has been defined. Tuns out that BuildBoardPolygonOutlines
is called with aErrorText set to nullptr an it tries to deference it to
write an error message when no board edges has been found.

The attached patch checks aErrorText and only deference it if it is not
nullptr.

Upon further investigation I discovered that the overloaded method
BOARD::GetBoardPolygonOutlines is called from ZONE_FILLER::Fill with its
default values of aErrorText and aErrorLocation (both nullptr). Wouldn't
be better to supply a valid pointer to aErrorText to inform the user
about the error / warning in this case?

Thanks,
Augusto.
>From f14e9a171d3e7e023b7778745c3b29f7119e9603 Mon Sep 17 00:00:00 2001
From: Augusto Fraga Giachero <augustofg96@xxxxxxxxx>
Date: Fri, 21 Aug 2020 08:36:17 -0300
Subject: [PATCH] Check the aErrortext pointer before deferencing it

BuildBoardPolygonOutlines can be called with aErrorText set to
nullptr (as it is when calling BOARD::GetBoardPolygonOutlines with its
default values).
---
 pcbnew/convert_drawsegment_list_to_polygon.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/pcbnew/convert_drawsegment_list_to_polygon.cpp b/pcbnew/convert_drawsegment_list_to_polygon.cpp
index aaf04b211..bd962f74a 100644
--- a/pcbnew/convert_drawsegment_list_to_polygon.cpp
+++ b/pcbnew/convert_drawsegment_list_to_polygon.cpp
@@ -785,7 +785,8 @@ bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines, wxStri
     }
     else
     {
-        *aErrorText = _( "No edges found on Edge.Cuts layer." );
+        if( aErrorText != nullptr )
+            *aErrorText = _( "No edges found on Edge.Cuts layer." );
     }
 
     if( !success || !aOutlines.OutlineCount() )
-- 
2.28.0


Follow ups