From c90622df7e4c032152641693b39364a2864abba9 Mon Sep 17 00:00:00 2001 From: Niki Date: Sat, 5 Apr 2025 10:29:11 +0200 Subject: [PATCH] array: get out of bounds -> NULL --- array.c | 4 ++++ array.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/array.c b/array.c index e5bb7ee..4b2faf6 100644 --- a/array.c +++ b/array.c @@ -198,6 +198,10 @@ void *array_next(array_t *me, void *ptr) { } void *array_get(array_t *me, size_t i) { + if (i < 0 || i >= me->count) { + return NULL; + } + priv_t *priv = (priv_t *) me->priv; // cast to (char *) because we want 'byte' arithmetic diff --git a/array.h b/array.h index d98989f..a4b8498 100644 --- a/array.h +++ b/array.h @@ -305,7 +305,7 @@ void *array_next(array_t *me, void *ptr); * * @param i the index of the element to retrieve * - * @note if the index is out of bounds, you will get invalid data + * @note if the index is out of bounds, you will get NULL * * @return the pointer to the i'th element */ -- 2.27.0