From 2033d9a6c5321d510ba760940ab4536edc25d996 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 8 Sep 2022 17:12:32 +0200 Subject: [PATCH] SCH_LABEL_BASE::ResolveTextVar(): Protect against null pointer It can happen in QA tests. --- eeschema/sch_label.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/eeschema/sch_label.cpp b/eeschema/sch_label.cpp index ef93a52763..b5c9f8ce1c 100644 --- a/eeschema/sch_label.cpp +++ b/eeschema/sch_label.cpp @@ -465,6 +465,9 @@ bool SCH_LABEL_BASE::ResolveTextVar( wxString* token, int aDepth ) const { if( token->Contains( ':' ) ) { + if( !Schematic() ) + return false; + if( Schematic()->ResolveCrossReference( token, aDepth ) ) return true; } @@ -523,10 +526,13 @@ bool SCH_LABEL_BASE::ResolveTextVar( wxString* token, int aDepth ) const if( sheet->ResolveTextVar( token, aDepth ) ) return true; } - else if( SCH_SHEET* sheet = Schematic()->CurrentSheet().Last() ) + else if( Schematic() ) { - if( sheet->ResolveTextVar( token, aDepth ) ) - return true; + if( SCH_SHEET* sheet = Schematic()->CurrentSheet().Last() ) + { + if( sheet->ResolveTextVar( token, aDepth ) ) + return true; + } } return false; @@ -882,7 +888,6 @@ void SCH_LABEL_BASE::Plot( PLOTTER* aPlotter, bool aBackground ) const static std::vector s_poly; RENDER_SETTINGS* settings = aPlotter->RenderSettings(); - SCHEMATIC* schematic = Schematic(); SCH_CONNECTION* connection = Connection(); int layer = ( connection && connection->IsBus() ) ? LAYER_BUS : m_layer; COLOR4D color = settings->GetLayerColor( layer );