From acc8cbd75f41d2352291c98d288731c2b483ad83 Mon Sep 17 00:00:00 2001 From: cozis Date: Tue, 2 Nov 2021 13:34:23 +0000 Subject: [PATCH] added maximum nested call limit --- samples/func.noja | 5 +++++ src/runtime/runtime.c | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/samples/func.noja b/samples/func.noja index 75913d2..13fad58 100644 --- a/samples/func.noja +++ b/samples/func.noja @@ -1,4 +1,9 @@ +fun k(k) + return k(); + +k(k); + fun x(a, b, c) print(a, b, c); diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index 6c0cf42..9153d03 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -4,6 +4,7 @@ #include "runtime.h" #define MAX_FRAME_STACK 16 +#define MAX_FRAMES 1024 typedef struct Frame Frame; @@ -674,6 +675,14 @@ Object *run(Runtime *runtime, Error *error, Executable *exe, int index, Object * assert(exe != NULL); assert(index >= 0); assert(argc >= 0); + + if(runtime->depth == MAX_FRAMES) + { + Error_Report(error, 1, "Maximum nested call limit of %d was reached", MAX_FRAMES); + return NULL; + } + + assert(runtime->depth < MAX_FRAMES); // Initialize the frame. Frame frame;