From 18c61d86dc3b7673d905ea567676d0fed4409f75 Mon Sep 17 00:00:00 2001 From: Jacob Signorovitch Date: Tue, 11 Mar 2025 17:56:04 +0900 Subject: [PATCH] Fixed crash on unknown var name. --- src/exec.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/exec.c b/src/exec.c index ce3604f..9f16165 100644 --- a/src/exec.c +++ b/src/exec.c @@ -114,7 +114,19 @@ AST* exec_vref(AST* ast) { log_dbg("attempting to reference var"); ASTVrefData* vref = (ASTVrefData*)ast->data; - return exec_exp(exec_find(vref->to)); + AST* found = exec_find(vref->to); + + if (found == NULL) { + // TODO: Better memory management here. + static char msg[256]; + snprintf( + msg, sizeof(msg), "Could not find value in scope for `%s`.", + vref->to + ); + return ast_init(AST_TYPE_EXC, msg); + } + + return exec_exp(found); } void exec_print(double n) { printf("= %lf\n", n); }