From 9675cf654d86464344e56705db7a71ea17f76c6f Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Apr 2016 13:00:21 +0200 Subject: Imported Upstream version 0.6.6+svn20070915 --- Vector.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'Vector.c') diff --git a/Vector.c b/Vector.c index 4ad697c..4c2a4f9 100644 --- a/Vector.c +++ b/Vector.c @@ -63,6 +63,7 @@ void Vector_delete(Vector* this) { #ifdef DEBUG static inline bool Vector_isConsistent(Vector* this) { + assert(this->items <= this->arraySize); if (this->owner) { for (int i = 0; i < this->items; i++) if (this->array[i] && this->array[i]->class != this->vectorType) @@ -73,6 +74,16 @@ static inline bool Vector_isConsistent(Vector* this) { } } +int Vector_count(Vector* this) { + int items = 0; + for (int i = 0; i < this->items; i++) { + if (this->array[i]) + items++; + } + assert(items == this->items); + return items; +} + #endif void Vector_prune(Vector* this) { @@ -222,8 +233,9 @@ void Vector_add(Vector* this, void* data_) { assert(data_ && ((Object*)data_)->class == this->vectorType); Object* data = data_; assert(Vector_isConsistent(this)); - + int i = this->items; Vector_set(this, this->items, data); + assert(this->items == i+1); (void)(i); assert(Vector_isConsistent(this)); } -- cgit v1.2.3