Fix off-by-one error in ByteVectorList::split

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@994815 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
Lukáš Lalinský 2009-07-11 13:24:21 +00:00
parent 5e1eb18df9
commit 39e6891c92
3 changed files with 40 additions and 1 deletions

View 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);

View 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

View File

@ -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);