Skip to content

Commit

Permalink
recreate last element of array with default constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz-h committed Jan 22, 2020
1 parent 36d7f6c commit a9d7532
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions vislib/include/vislib/Array.h
Expand Up @@ -744,21 +744,16 @@ namespace vislib {
void Array<T, L, C>::Erase(const SIZE_T idx) {
this->Lock();
if (idx < this->count) {
/* Destruct element to erase. */
// WTF?
// Object is destroyed, but below operator =() is used on this object.
// This is undefined behavior.
//C::Dtor(this->elements + idx);

/* Move elements forward. */
for (SIZE_T i = idx + 1; i < this->count; i++) {
this->elements[i - 1] = this->elements[i];
}
this->count--;

/* Element after valid range must now be reconstructed. */
// WTF?
//C::Ctor(this->elements + this->count);
/* Recreate last element with default constructor to overwrite old
* object. Assume that default constructed object is smaller to
* save memory in case the old object was big. */
this->elements[this->count] = T();
}
this->Unlock();
}
Expand Down

0 comments on commit a9d7532

Please sign in to comment.