From f90b04c715e4580db946cd42a2cf5ea94c7c392e Mon Sep 17 00:00:00 2001
From: Jeff Young <jeff@rokeby.ie>
Date: Wed, 18 Jan 2023 01:05:27 +0000
Subject: [PATCH] Nullptr safety.  (Sentry KICAD-5N)

---
 pcbnew/exporters/export_gencad.cpp | 47 ++++++++++++++++--------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/pcbnew/exporters/export_gencad.cpp b/pcbnew/exporters/export_gencad.cpp
index 26faf68911..dcde63d337 100644
--- a/pcbnew/exporters/export_gencad.cpp
+++ b/pcbnew/exporters/export_gencad.cpp
@@ -935,32 +935,35 @@ static void CreateSignalsSection( FILE* aFile, BOARD* aPcb )
     {
         net = aPcb->FindNet( ii );
 
-        if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection)
+        if( net )
         {
-            msg.Printf( wxT( "NoConnection%d" ), NbNoConn++ );
-        }
-
-        if( net->GetNetCode() <= 0 )  // dummy netlist (no connection)
-            continue;
-
-        msg = wxT( "SIGNAL \"" ) + escapeString( net->GetNetname() ) + wxT( "\"" );
-
-        fputs( TO_UTF8( msg ), aFile );
-        fputs( "\n", aFile );
-
-        for( FOOTPRINT* footprint : aPcb->Footprints() )
-        {
-            for( PAD* pad : footprint->Pads() )
+            if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection)
             {
-                if( pad->GetNetCode() != net->GetNetCode() )
-                    continue;
+                msg.Printf( wxT( "NoConnection%d" ), NbNoConn++ );
+            }
 
-                msg.Printf( wxT( "NODE \"%s\" \"%s\"" ),
-                            escapeString( footprint->GetReference() ),
-                            escapeString( pad->GetNumber() ) );
+            if( net->GetNetCode() <= 0 )  // dummy netlist (no connection)
+                continue;
 
-                fputs( TO_UTF8( msg ), aFile );
-                fputs( "\n", aFile );
+            msg = wxT( "SIGNAL \"" ) + escapeString( net->GetNetname() ) + wxT( "\"" );
+
+            fputs( TO_UTF8( msg ), aFile );
+            fputs( "\n", aFile );
+
+            for( FOOTPRINT* footprint : aPcb->Footprints() )
+            {
+                for( PAD* pad : footprint->Pads() )
+                {
+                    if( pad->GetNetCode() != net->GetNetCode() )
+                        continue;
+
+                    msg.Printf( wxT( "NODE \"%s\" \"%s\"" ),
+                                escapeString( footprint->GetReference() ),
+                                escapeString( pad->GetNumber() ) );
+
+                    fputs( TO_UTF8( msg ), aFile );
+                    fputs( "\n", aFile );
+                }
             }
         }
     }