git://git.nikiroo.be
/
cutils.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
898baa7
)
array: get out of bounds -> NULL
author
Niki
<niki@nikiroo.be>
Sat, 5 Apr 2025 08:29:11 +0000
(10:29 +0200)
committer
Niki
<niki@nikiroo.be>
Sat, 5 Apr 2025 08:29:11 +0000
(10:29 +0200)
array.c
patch
|
blob
|
blame
|
history
array.h
patch
|
blob
|
blame
|
history
diff --git
a/array.c
b/array.c
index e5bb7eed05eae387a881ab78764fe87773f7b8d6..4b2faf6a4c6cbfe524416c3edd32b162c0cc9f79 100644
(file)
--- 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 d98989fc44955ec2d291ba421e5f844da9121dcf..a4b849837994ca8a34693f6e08af7d8debbbc572 100644
(file)
--- 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
*/