diff --git a/include/interp.h b/include/interp.h index 8b9aad9..7b17daa 100644 --- a/include/interp.h +++ b/include/interp.h @@ -32,11 +32,14 @@ typedef struct { int option_base; /* Control flow stacks */ - for_entry_t for_stack[16]; +#define MAX_FOR_DEPTH 16 +#define MAX_GOSUB_DEPTH 24 +#define MAX_WHILE_DEPTH 16 + for_entry_t for_stack[MAX_FOR_DEPTH]; int for_sp; - gosub_entry_t gosub_stack[24]; + gosub_entry_t gosub_stack[MAX_GOSUB_DEPTH]; int gosub_sp; - while_entry_t while_stack[16]; + while_entry_t while_stack[MAX_WHILE_DEPTH]; int while_sp; /* DEF FN */ diff --git a/src/interp.c b/src/interp.c index 7438e4a..d297de0 100644 --- a/src/interp.c +++ b/src/interp.c @@ -1509,7 +1509,7 @@ void gw_exec_stmt(void) program_line_t *target = gw_find_line(num); if (!target) gw_error(ERR_UL); - if (gw.gosub_sp >= 24) + if (gw.gosub_sp >= MAX_GOSUB_DEPTH) gw_error(ERR_OM); gw.gosub_stack[gw.gosub_sp].ret_text = gw.text_ptr; gw.gosub_stack[gw.gosub_sp].ret_line = gw.cur_line; @@ -1593,7 +1593,7 @@ void gw_exec_stmt(void) } } - if (gw.for_sp >= 16) + if (gw.for_sp >= MAX_FOR_DEPTH) gw_error(ERR_OM); for_entry_t *f = &gw.for_stack[gw.for_sp++]; @@ -1759,7 +1759,7 @@ void gw_exec_stmt(void) } } if (!found) { - if (gw.while_sp >= 16) + if (gw.while_sp >= MAX_WHILE_DEPTH) gw_error(ERR_OM); gw.while_stack[gw.while_sp].while_text = while_text; gw.while_stack[gw.while_sp].while_line = while_line; @@ -1887,7 +1887,7 @@ void gw_exec_stmt(void) if (!target) gw_error(ERR_UL); if (is_gosub) { - if (gw.gosub_sp >= 24) + if (gw.gosub_sp >= MAX_GOSUB_DEPTH) gw_error(ERR_OM); gw.gosub_stack[gw.gosub_sp].ret_text = gw.text_ptr; gw.gosub_stack[gw.gosub_sp].ret_line = gw.cur_line;