From a35698f08a2e7012c17ffe30646bac7a496e3c17 Mon Sep 17 00:00:00 2001
From: Jeff Young <jeff@rokeby.ie>
Date: Tue, 1 Sep 2020 17:34:35 +0100
Subject: [PATCH] Don't fire non-well-formed rules.  (But don't assert either.)

Fixes https://gitlab.com/kicad/code/kicad/issues/5443
---
 common/libeval_compiler/libeval_compiler.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/common/libeval_compiler/libeval_compiler.cpp b/common/libeval_compiler/libeval_compiler.cpp
index e841d675a6..93d3e8cf40 100644
--- a/common/libeval_compiler/libeval_compiler.cpp
+++ b/common/libeval_compiler/libeval_compiler.cpp
@@ -1022,10 +1022,15 @@ void UOP::Exec( CONTEXT* ctx )
 
 VALUE* UCODE::Run( CONTEXT* ctx )
 {
+    static VALUE g_false( 0 );
+
     for( UOP* op : m_ucode )
         op->Exec( ctx );
 
-    assert( ctx->SP() == 1 );
+    // non-well-formed rules should not be fired
+    if( ctx->SP() != 1 )
+        return &g_false;
+
     return ctx->Pop();
 }