From 77c9c39295dca55dd175ebd79545d3d6a1e0cf4c Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Mon, 5 Jul 2021 01:13:45 -0400 Subject: [PATCH] Check indexes etc for `at` --- src/object.h | 3 ++- src/pebblisp.c | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/object.h b/src/object.h index df7b8e4..ff4e220 100644 --- a/src/object.h +++ b/src/object.h @@ -40,7 +40,8 @@ enum errorCode { NOT_A_LIST, SCRIPT_NOT_FOUND, NO_CLONE_SPECIFIED, - CAN_ONLY_EVAL_STRINGS + CAN_ONLY_EVAL_STRINGS, + INDEX_PAST_END, }; #define MALLOC_FLAG 64 diff --git a/src/pebblisp.c b/src/pebblisp.c index 77e029b..55cd717 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -462,7 +462,12 @@ Object prepend(Object list, Object newElement, struct Environment *env) Object at(Object index, Object list, struct Environment *env) { - return cloneObject(*itemAt(&list, index.number)); + const Object *found = itemAt(&list, index.number); + if(found) { + return cloneObject(*found); + } else { + return errorObject(INDEX_PAST_END); + } } Object rest(Object list, Object ignore, struct Environment *env)