From: Tsuda Kageyu Date: Sat, 16 May 2015 02:16:00 +0000 (+0900) Subject: Revert the last two commits. X-Git-Tag: v1.10beta~114^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b021ed44e95647fb37ca8cc2cb312bd8a6ed9347;p=taglib Revert the last two commits. But leave the tests unchanged, and add some comments. --- diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index ad5d4523..45ad0317 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -703,15 +703,12 @@ ByteVector &ByteVector::resize(uint size, char padding) if(size != d->length) { detach(); - const size_t bufferSize = d->data->data.size(); + // Remove the excessive length of the internal buffer first to pad correctly. + // This doesn't reallocate the buffer, since std::vector::resize() doesn't + // reallocate the buffer when shrinking. - if(size > bufferSize - d->offset) { - d->data->data.resize(d->offset + size, padding); - ::memset(&*end(), padding, bufferSize - (d->length + d->offset)); - } - else if(size > d->length) { - ::memset(&*end(), padding, size - d->length); - } + d->data->data.resize(d->offset + d->length); + d->data->data.resize(d->offset + size, padding); d->length = size; }