diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 62f0fbef..841b5667 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -554,12 +554,16 @@ int ByteVector::endsWithPartialMatch(const ByteVector &pattern) const ByteVector &ByteVector::append(const ByteVector &v) { - if(v.d->length != 0) { - detach(); - unsigned int originalSize = size(); - resize(originalSize + v.size()); - ::memcpy(data() + originalSize, v.data(), v.size()); - } + if(v.isEmpty()) + return *this; + + detach(); + + const unsigned int originalSize = size(); + const unsigned int appendSize = v.size(); + + resize(originalSize + v.size()); + ::memcpy(data() + originalSize, v.data(), appendSize); return *this; } diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp index 32968965..12393b50 100644 --- a/tests/test_bytevector.cpp +++ b/tests/test_bytevector.cpp @@ -48,7 +48,8 @@ class TestByteVector : public CppUnit::TestFixture CPPUNIT_TEST(testReplace); CPPUNIT_TEST(testIterator); CPPUNIT_TEST(testResize); - CPPUNIT_TEST(testAppend); + CPPUNIT_TEST(testAppend1); + CPPUNIT_TEST(testAppend2); CPPUNIT_TEST(testBase64); CPPUNIT_TEST_SUITE_END(); @@ -403,7 +404,7 @@ public: CPPUNIT_ASSERT_EQUAL(-1, c.find('C')); } - void testAppend() + void testAppend1() { ByteVector v1("foo"); v1.append("bar"); @@ -441,6 +442,13 @@ public: CPPUNIT_ASSERT_EQUAL(ByteVector("taglib"), v8); } + void testAppend2() + { + ByteVector a("1234"); + a.append(a); + CPPUNIT_ASSERT_EQUAL(ByteVector("12341234"), a); + } + void testBase64() { ByteVector sempty;