From 02712484729265fa6b5dbe3b40c873ccff1e2bbf Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 21 Jan 2017 20:30:01 -0800 Subject: [PATCH] Add two extra checks to ensure there are no negative array indices. --- src/sprs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sprs.c b/src/sprs.c index ac9bd33..1166d5a 100644 --- a/src/sprs.c +++ b/src/sprs.c @@ -36,7 +36,7 @@ void sprs_put(sprs* sprs, int index, void* data){ } } int sprs_contains(sprs* sprs, int index){ - return sprs->sparse[index].index < sprs->size && sprs->dense[sprs->sparse[index].index] == index; + return index >= 0 && sprs->sparse[index].index >= 0 && sprs->sparse[index].index < sprs->size && sprs->dense[sprs->sparse[index].index] == index; } void* sprs_get(sprs* sprs, int index){ void* data = NULL;