Assert Vector_get returns an object

It is generally assumed Vector_get returns a non-NULL object.
Use a generic assert in Vector_get instead of in callers.
This commit is contained in:
Christian Göttsche 2020-10-31 20:57:22 +01:00 committed by cgzones
parent 742e610f1d
commit 0806a7958b
2 changed files with 2 additions and 3 deletions

View File

@ -261,7 +261,6 @@ void Panel_draw(Panel* this, bool focus) {
int line = 0; int line = 0;
for(int i = first; line < h && i < upTo; i++) { for(int i = first; line < h && i < upTo; i++) {
Object* itemObj = Vector_get(this->items, i); Object* itemObj = Vector_get(this->items, i);
assert(itemObj); if(!itemObj) continue;
RichString_begin(item); RichString_begin(item);
Object_display(itemObj, &item); Object_display(itemObj, &item);
int itemLen = RichString_sizeVal(item); int itemLen = RichString_sizeVal(item);
@ -288,7 +287,6 @@ void Panel_draw(Panel* this, bool focus) {
} else { } else {
Object* oldObj = Vector_get(this->items, this->oldSelected); Object* oldObj = Vector_get(this->items, this->oldSelected);
assert(oldObj);
RichString_begin(old); RichString_begin(old);
Object_display(oldObj, &old); Object_display(oldObj, &old);
int oldLen = RichString_sizeVal(old); int oldLen = RichString_sizeVal(old);

View File

@ -65,8 +65,9 @@ int Vector_count(const Vector* this) {
} }
Object* Vector_get(Vector* this, int idx) { Object* Vector_get(Vector* this, int idx) {
assert(idx < this->items); assert(idx >= 0 && idx < this->items);
assert(Vector_isConsistent(this)); assert(Vector_isConsistent(this));
assert(this->array[idx]);
return this->array[idx]; return this->array[idx];
} }