From f9ed5f3fb81501aef609d8d951e09353f2528dff Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Thu, 7 Nov 2024 10:40:00 +0100 Subject: [PATCH] additional cleanup: fixes the cleanup of NULL routines --- lib.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib.c b/lib.c index feed13f..672e1bc 100644 --- a/lib.c +++ b/lib.c @@ -1207,12 +1207,16 @@ void ink_clean_routines(struct context* ctx) { null.type = INK_INTEGER; for(i = 0; i < ctx->routines_top; ++i) { if(ctx->routines[i].panic == INK_ROUTINE_CAN_REUSE || ctx->routines[i].panic == INK_ROUTINE_SUCCESS) { - for (j = 0; j < ctx->routines[i].top; ++j) { - ctx->routines[i].stack[j] = null; + if(ctx->routines[i].stack != NULL) { + for (j = 0; j < ctx->routines[i].top; ++j) { + ctx->routines[i].stack[j] = null; + } } - for (j = 0; j < ctx->routines[i].function_stack_top; ++j) { - ctx->routines[i].function_stack[j].executing = null; - ctx->routines[i].function_stack[j].index = 0; + if(ctx->routines[i].function_stack != NULL) { + for (j = 0; j < ctx->routines[i].function_stack_top; ++j) { + ctx->routines[i].function_stack[j].executing = null; + ctx->routines[i].function_stack[j].index = 0; + } } ctx->routines[i].top = 0; ctx->routines[i].function_stack_top = 0;