]> granicus.if.org Git - taglib/commitdiff
Fix the wrong padding of ByteVector::resize().
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 1 May 2015 17:34:40 +0000 (02:34 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 1 May 2015 17:43:08 +0000 (02:43 +0900)
The expanded area will be filled with garbage instead of correct padding in some corner cases.

taglib/toolkit/tbytevector.cpp
tests/test_bytevector.cpp

index 4ae40666b5a60ecc56c8bfeb34727279caef4ec8..bf6c525ff56a60e4a1db4220fe40d2344c12afb8 100644 (file)
@@ -702,6 +702,7 @@ ByteVector &ByteVector::resize(uint size, char padding)
 {
   if(size != d->length) {
     detach();
+    d->data->data.resize(d->offset + d->length);
     d->data->data.resize(d->offset + size, padding);
     d->length = size;
   }
index c68a8c340648c7a219fff82173cac5795e73d2a3..e9d43c0520a55d0eee5087ae70618f47bec55012 100644 (file)
@@ -123,6 +123,12 @@ public:
     CPPUNIT_ASSERT(i.containsAt(j, 5, 0));
     CPPUNIT_ASSERT(i.containsAt(j, 6, 1));
     CPPUNIT_ASSERT(i.containsAt(j, 6, 1, 3));
+
+    ByteVector k = ByteVector("0123456789").mid(3, 4);
+    k.resize(6, 'A');
+    CPPUNIT_ASSERT_EQUAL(uint(6), k.size());
+    CPPUNIT_ASSERT_EQUAL('6', k[3]);
+    CPPUNIT_ASSERT_EQUAL('A', k[4]);
   }
 
   void testFind1()