@@ -1659,3 +1659,31 @@ TEST(VirtualMachineTest, NoCrashInNestedLoopsInIfElseStatements)
1659
1659
vm.run ();
1660
1660
ASSERT_EQ (vm.registerCount (), 0 );
1661
1661
}
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