aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-22 20:30:17 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-22 20:30:17 +0100
commitbc0e0fce252630110d6b0d18e55aac129b3d6d35 (patch)
treefafbaa594dc97af14b7a5f41f67e5b12d1d7beb0 /src
parent9da31398baa93e8485aa70fc09cbca66daa0fa40 (diff)
downloadovm-bc0e0fce252630110d6b0d18e55aac129b3d6d35.tar.gz
ovm-bc0e0fce252630110d6b0d18e55aac129b3d6d35.tar.bz2
ovm-bc0e0fce252630110d6b0d18e55aac129b3d6d35.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/runtime.c3
1 files changed, 2 insertions, 1 deletions
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);