From 84425f5a4002fa365e77bde47903587700a3a8a5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 12 Aug 2020 16:26:10 +0100 Subject: [PATCH] Fix crash bug from bad static_cast. --- include/libeval_compiler/libeval_compiler.h | 2 +- pcbnew/pcb_expr_evaluator.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/libeval_compiler/libeval_compiler.h b/include/libeval_compiler/libeval_compiler.h index 3fe783598e..232fb4f4da 100644 --- a/include/libeval_compiler/libeval_compiler.h +++ b/include/libeval_compiler/libeval_compiler.h @@ -241,7 +241,7 @@ public: class CONTEXT { public: - ~CONTEXT() + virtual ~CONTEXT() { for( VALUE* value : m_ownedValues ) delete value; diff --git a/pcbnew/pcb_expr_evaluator.cpp b/pcbnew/pcb_expr_evaluator.cpp index 652245fd96..84fb057f2e 100644 --- a/pcbnew/pcb_expr_evaluator.cpp +++ b/pcbnew/pcb_expr_evaluator.cpp @@ -215,6 +215,8 @@ PCB_EXPR_BUILTIN_FUNCTIONS::PCB_EXPR_BUILTIN_FUNCTIONS() BOARD_ITEM* PCB_EXPR_VAR_REF::GetObject( LIBEVAL::CONTEXT* aCtx ) const { + wxASSERT( dynamic_cast( aCtx ) ); + const PCB_EXPR_CONTEXT* ctx = static_cast( aCtx ); BOARD_ITEM* item = ctx->GetItem( m_itemIndex ); return item; @@ -381,11 +383,11 @@ PCB_EXPR_EVALUATOR::~PCB_EXPR_EVALUATOR() bool PCB_EXPR_EVALUATOR::Evaluate( const wxString& aExpr ) { PCB_EXPR_UCODE ucode; - LIBEVAL::CONTEXT preflightContext; + PCB_EXPR_CONTEXT preflightContext( F_Cu ); m_compiler.Compile( aExpr.ToUTF8().data(), &ucode, &preflightContext ); - LIBEVAL::CONTEXT evaluationContext; + PCB_EXPR_CONTEXT evaluationContext( F_Cu ); LIBEVAL::VALUE* result = ucode.Run( &evaluationContext ); if( result->GetType() == LIBEVAL::VT_NUMERIC )