]> granicus.if.org Git - taglib/commitdiff
ByteVector::append() can't take the vector itself.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Sat, 20 Feb 2016 10:42:46 +0000 (19:42 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Sat, 20 Feb 2016 10:42:46 +0000 (19:42 +0900)
taglib/toolkit/tbytevector.cpp
tests/test_bytevector.cpp

index 62f0fbef02774b1e54f1c8a18f29b33a86608311..841b56676f7a24bc2a6eac50bdfedfa4b2870a95 100644 (file)
@@ -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;
 }
index 329689658383e4ae0fc0fd7d60ffeba6eb8a161d..12393b5004c495a8fac23e0db1fb976b6e011165 100644 (file)
@@ -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;