From: Niki Date: Sat, 5 Apr 2025 08:29:11 +0000 (+0200) Subject: array: get out of bounds -> NULL X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=c90622df7e4c032152641693b39364a2864abba9;p=cutils.git array: get out of bounds -> NULL --- 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 */