From 2e4a8e8edd2799aff6258225853995d9b40840a8 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 4 Jan 2026 09:12:35 +0900 Subject: [PATCH] mruby-compiler: fix sp tracking in pattern match failure path After pattern matching code generation, the sp (stack pointer) must be restored to match the success path value. The failure path (after RAISEIF) left sp in a different state, causing incorrect register allocation in subsequent code like string interpolation. This caused OP_STRCAT to use the wrong register, leading to null-dereference when trying to modify a non-string value as a string. Co-authored-by: Claude --- mrbgems/mruby-compiler/core/codegen.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 3651d53c3..bddf40c4e 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -6667,6 +6667,9 @@ codegen(codegen_scope *s, node *tree, int val) /* End of pattern matching */ dispatch(s, match_pos); + /* Restore sp to match success path value */ + s->sp = saved_sp - 1; + if (val) push(); } else { /* Pattern always matches - pop value and push result if needed */