mirror of
https://github.com/taglib/taglib.git
synced 2025-06-04 01:28:21 -04:00
Fix off-by-one error in ByteVector::find.
In case where the pattern has the same length as the bytevector, it should degrade to A == B, not just return "not found" (e.g. A.find(A) should return 0, not -1). git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@735107 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
parent
b44cee48f4
commit
41bc6f0686
@ -95,7 +95,7 @@ namespace TagLib {
|
||||
template <class Vector>
|
||||
int vectorFind(const Vector &v, const Vector &pattern, uint offset, int byteAlign)
|
||||
{
|
||||
if(pattern.size() > v.size() || offset >= v.size() - 1)
|
||||
if(pattern.size() > v.size() || offset > v.size() - 1)
|
||||
return -1;
|
||||
|
||||
// Let's go ahead and special case a pattern of size one since that's common
|
||||
|
@ -34,6 +34,7 @@ class TestByteVector : public CppUnit::TestFixture
|
||||
CPPUNIT_TEST_SUITE(TestByteVector);
|
||||
CPPUNIT_TEST(testByteVector);
|
||||
CPPUNIT_TEST(testFind1);
|
||||
CPPUNIT_TEST(testFind2);
|
||||
CPPUNIT_TEST(testRfind1);
|
||||
CPPUNIT_TEST(testRfind2);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
@ -128,6 +129,14 @@ public:
|
||||
CPPUNIT_ASSERT_EQUAL(-1, ByteVector("....SggO."). find("SggO", 8));
|
||||
}
|
||||
|
||||
void testFind2()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL(0, ByteVector("\x01", 1).find("\x01"));
|
||||
CPPUNIT_ASSERT_EQUAL(0, ByteVector("\x01\x02", 2).find("\x01\x02"));
|
||||
CPPUNIT_ASSERT_EQUAL(-1, ByteVector("\x01", 1).find("\x02"));
|
||||
CPPUNIT_ASSERT_EQUAL(-1, ByteVector("\x01\x02", 2).find("\x01\x03"));
|
||||
}
|
||||
|
||||
void testRfind1()
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL(-1, ByteVector(".OggS....").rfind("OggS", 0));
|
||||
|
Loading…
x
Reference in New Issue
Block a user