mirror of
https://github.com/taglib/taglib.git
synced 2025-05-27 21:20:26 -04:00
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:
parent
5e1eb18df9
commit
39e6891c92
@ -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);
|
||||
|
@ -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
|
||||
|
38
tests/test_bytevectorlist.cpp
Normal file
38
tests/test_bytevectorlist.cpp
Normal 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);
|
Loading…
Reference in New Issue
Block a user