From: Matthias Kruk Date: Sun, 2 May 2021 11:39:05 +0000 (+0900) Subject: array: Make array_get() return an error if an element wasn't set X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=8663f98b156ab3a9c146c418ed93e157da3e39a1;p=mwm array: Make array_get() return an error if an element wasn't set The array_get() function returns success when an entry is retrieved that was never set. This makes it hard to distinguish uninitialized entries. This commit changes array_get() to return an error if the caller is attempting to retrieve an uninitialized entry. --- diff --git a/array.c b/array.c index 3a143de..325e68b 100644 --- a/array.c +++ b/array.c @@ -208,8 +208,12 @@ int array_get(struct array *array, int idx, void **data) } real_idx = idx % array->size; - *data = array->data[real_idx]; + if(!array->flags[real_idx]) { + return(-ENOENT); + } + + *data = array->data[real_idx]; return(0); }