Skip to content

Commit

Permalink
vm: Fix ExitBlock crashing when stack only contains one element
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddiM8 committed Dec 5, 2024
1 parent 3b56b6a commit 6085cce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Vm/InstructionExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ private void UnpackUpper(byte count)

private void ExitBlock(byte popCount)
{
if (_stack.Count == 1)
return;

var returnValue = _stack.Pop();
for (byte i = 0; i < popCount; i++)
Pop();
Expand Down
3 changes: 2 additions & 1 deletion src/Vm/InstructionGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ private void ExitBlock(bool isPrimaryExitPoint, int? newScopeDepth = null)
if (popCount > byte.MaxValue)
throw new RuntimeException("Too many variables in block");

Emit(InstructionKind.ExitBlock, (byte)popCount);
if (popCount > 0)
Emit(InstructionKind.ExitBlock, (byte)popCount);
}

private void ClearBlock(bool isPrimaryExitPoint, int? newScopeDepth = null)
Expand Down

0 comments on commit 6085cce

Please sign in to comment.