Skip to content

Commit 1590f63

Browse files
committed
fix #387: Do not clear procedure arguments when stopping the VM
1 parent 7fa848d commit 1590f63

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/engine/virtualmachine_p.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,6 @@ do_exec : {
731731
}
732732
if (stop) {
733733
stop = false;
734-
callTree.clear();
735-
procedureArgTree.clear();
736-
procedureArgs = nullptr;
737-
nextProcedureArgs = nullptr;
738734
if (goBack) {
739735
goBack = false;
740736
pos -= instruction_arg_count[OP_EXEC] + 1;

test/virtual_machine/virtual_machine_test.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,3 +1659,31 @@ TEST(VirtualMachineTest, NoCrashInNestedLoopsInIfElseStatements)
16591659
vm.run();
16601660
ASSERT_EQ(vm.registerCount(), 0);
16611661
}
1662+
1663+
TEST(VirtualMachineTest, NoCrashWhenReadingProcedureArgsAfterStopping)
1664+
{
1665+
// Regtest for #387
1666+
static unsigned int bytecode[] = { OP_START, OP_INIT_PROCEDURE, OP_CONST, 0, OP_ADD_ARG, OP_CALL_PROCEDURE, 0, OP_HALT };
1667+
static unsigned int procedure[] = { OP_START, OP_NULL, OP_EXEC, 0, OP_READ_ARG, 0, OP_PRINT, OP_HALT };
1668+
static unsigned int *procedures[] = { procedure };
1669+
static BlockFunc functions[] = { &testFunction3 };
1670+
static Value constValues[] = { "test" };
1671+
1672+
VirtualMachine vm(nullptr, nullptr, nullptr);
1673+
vm.setBytecode(bytecode);
1674+
vm.setProcedures(procedures);
1675+
vm.setFunctions(functions);
1676+
vm.setConstValues(constValues);
1677+
1678+
testing::internal::CaptureStdout();
1679+
vm.run();
1680+
ASSERT_TRUE(testing::internal::GetCapturedStdout().empty());
1681+
ASSERT_EQ(vm.registerCount(), 0);
1682+
ASSERT_FALSE(vm.atEnd());
1683+
1684+
testing::internal::CaptureStdout();
1685+
vm.run();
1686+
ASSERT_EQ(testing::internal::GetCapturedStdout(), "test\n");
1687+
ASSERT_EQ(vm.registerCount(), 0);
1688+
ASSERT_TRUE(vm.atEnd());
1689+
}

0 commit comments

Comments
 (0)