Add two extra checks to ensure there are no negative array indices.

This commit is contained in:
Danila Fedorin 2017-01-21 20:30:01 -08:00
parent 5247394d35
commit 0271248472

View File

@ -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;