Skip to content

Commit 0806a79

Browse files
committed
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.
1 parent 742e610 commit 0806a79

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

Panel.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ void Panel_draw(Panel* this, bool focus) {
261261
int line = 0;
262262
for(int i = first; line < h && i < upTo; i++) {
263263
Object* itemObj = Vector_get(this->items, i);
264-
assert(itemObj); if(!itemObj) continue;
265264
RichString_begin(item);
266265
Object_display(itemObj, &item);
267266
int itemLen = RichString_sizeVal(item);
@@ -288,7 +287,6 @@ void Panel_draw(Panel* this, bool focus) {
288287

289288
} else {
290289
Object* oldObj = Vector_get(this->items, this->oldSelected);
291-
assert(oldObj);
292290
RichString_begin(old);
293291
Object_display(oldObj, &old);
294292
int oldLen = RichString_sizeVal(old);

Vector.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ int Vector_count(const Vector* this) {
6565
}
6666

6767
Object* Vector_get(Vector* this, int idx) {
68-
assert(idx < this->items);
68+
assert(idx >= 0 && idx < this->items);
6969
assert(Vector_isConsistent(this));
70+
assert(this->array[idx]);
7071
return this->array[idx];
7172
}
7273

0 commit comments

Comments
 (0)