Fixed bug in vm_execute_all, if no OP_HALT then program kept going

This adds a bound on vm_execute_all to stop program->ptr from going
past program->max.
This commit is contained in:
2023-10-22 20:30:17 +01:00
parent 9da31398ba
commit bc0e0fce25

View File

@@ -129,7 +129,8 @@ void vm_execute_all(vm_t *vm)
size_t cycles = 0;
size_t prev_sptr = 0;
#endif
while (program->instructions[program->ptr].opcode != OP_HALT)
while (program->instructions[program->ptr].opcode != OP_HALT &&
program->ptr < program->max)
{
#if VERBOSE >= 1
fprintf(stdout, "[vm_execute_all]: Trace(Cycle %lu)\n", cycles);