Skip to content

Commit 2e4a8e8

Browse files
matzclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 099d2c4 commit 2e4a8e8

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

mrbgems/mruby-compiler/core/codegen.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6667,6 +6667,9 @@ codegen(codegen_scope *s, node *tree, int val)
66676667

66686668
/* End of pattern matching */
66696669
dispatch(s, match_pos);
6670+
/* Restore sp to match success path value */
6671+
s->sp = saved_sp - 1;
6672+
if (val) push();
66706673
}
66716674
else {
66726675
/* Pattern always matches - pop value and push result if needed */

0 commit comments

Comments
 (0)