From bc0e0fce252630110d6b0d18e55aac129b3d6d35 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 22 Oct 2023 20:30:17 +0100 Subject: 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. --- src/runtime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/runtime.c b/src/runtime.c index 241d664..c2c793c 100644 --- a/src/runtime.c +++ b/src/runtime.c @@ -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); -- cgit v1.2.3-13-gbd6f