]> granicus.if.org Git - taglib/commitdiff
Fix off-by-one error in ByteVectorList::split
authorLukáš Lalinský <lalinsky@gmail.com>
Sat, 11 Jul 2009 13:24:21 +0000 (13:24 +0000)
committerLukáš Lalinský <lalinsky@gmail.com>
Sat, 11 Jul 2009 13:24:21 +0000 (13:24 +0000)
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@994815 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

taglib/toolkit/tbytevectorlist.cpp
tests/CMakeLists.txt
tests/test_bytevectorlist.cpp [new file with mode: 0644]

index 71d6f69d143712e2f617ddcbc5964348a0b186eb..b0553d264705eacd9924b45f0a22850dabafd7e5 100644 (file)
@@ -52,7 +52,7 @@ ByteVectorList ByteVectorList::split(const ByteVector &v, const ByteVector &patt
       offset != -1 && (max == 0 || max > int(l.size()) + 1);
       offset = v.find(pattern, offset + pattern.size(), byteAlign))
   {
-    if(offset - previousOffset > 1)
+    if(offset - previousOffset >= 1)
       l.append(v.mid(previousOffset, offset - previousOffset));
     else
       l.append(ByteVector::null);
index 18b62a54a7f95fb150d5c3961bb0582cf5d766dc..6afefe6da91eb8d137cf4f0e3fbba28e1384f599 100644 (file)
@@ -21,6 +21,7 @@ SET(test_runner_SRCS
   test_synchdata.cpp
   test_trueaudio.cpp
   test_bytevector.cpp
+  test_bytevectorlist.cpp
   test_string.cpp
   test_fileref.cpp
   test_id3v1.cpp
diff --git a/tests/test_bytevectorlist.cpp b/tests/test_bytevectorlist.cpp
new file mode 100644 (file)
index 0000000..f090fcd
--- /dev/null
@@ -0,0 +1,38 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <tbytevector.h>
+#include <tbytevectorlist.h>
+
+using namespace std;
+using namespace TagLib;
+
+class TestByteVectorList : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE(TestByteVectorList);
+  CPPUNIT_TEST(testSplitSingleChar);
+  CPPUNIT_TEST(testSplitSingleChar_2);
+  CPPUNIT_TEST_SUITE_END();
+
+public:
+
+  void testSplitSingleChar()
+  {
+    ByteVector v("a b");
+
+    ByteVectorList l = ByteVectorList::split(v, " ");
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(2), l.size());
+    CPPUNIT_ASSERT_EQUAL(ByteVector("a"), l[0]);
+    CPPUNIT_ASSERT_EQUAL(ByteVector("b"), l[1]);
+  }
+
+  void testSplitSingleChar_2()
+  {
+    ByteVector v("a");
+
+    ByteVectorList l = ByteVectorList::split(v, " ");
+    CPPUNIT_ASSERT_EQUAL(TagLib::uint(1), l.size());
+    CPPUNIT_ASSERT_EQUAL(ByteVector("a"), l[0]);
+  }
+
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TestByteVectorList);