@@ -1687,3 +1687,31 @@ TEST(VirtualMachineTest, NoCrashInNestedLoopsInIfElseStatements)
1687
1687
vm.run ();
1688
1688
ASSERT_EQ (vm.registerCount (), 0 );
1689
1689
}
1690
+
1691
+ TEST (VirtualMachineTest, NoCrashWhenReadingProcedureArgsAfterStopping)
1692
+ {
1693
+ // Regtest for #387
1694
+ static unsigned int bytecode[] = { OP_START, OP_INIT_PROCEDURE, OP_CONST, 0 , OP_ADD_ARG, OP_CALL_PROCEDURE, 0 , OP_HALT };
1695
+ static unsigned int procedure[] = { OP_START, OP_NULL, OP_EXEC, 0 , OP_READ_ARG, 0 , OP_PRINT, OP_HALT };
1696
+ static unsigned int *procedures[] = { procedure };
1697
+ static BlockFunc functions[] = { &testFunction3 };
1698
+ static Value constValues[] = { " test" };
1699
+
1700
+ VirtualMachine vm (nullptr , nullptr , nullptr );
1701
+ vm.setBytecode (bytecode);
1702
+ vm.setProcedures (procedures);
1703
+ vm.setFunctions (functions);
1704
+ vm.setConstValues (constValues);
1705
+
1706
+ testing::internal::CaptureStdout ();
1707
+ vm.run ();
1708
+ ASSERT_TRUE (testing::internal::GetCapturedStdout ().empty ());
1709
+ ASSERT_EQ (vm.registerCount (), 0 );
1710
+ ASSERT_FALSE (vm.atEnd ());
1711
+
1712
+ testing::internal::CaptureStdout ();
1713
+ vm.run ();
1714
+ ASSERT_EQ (testing::internal::GetCapturedStdout (), " test\n " );
1715
+ ASSERT_EQ (vm.registerCount (), 0 );
1716
+ ASSERT_TRUE (vm.atEnd ());
1717
+ }
0 commit comments