diff --git a/taglib/toolkit/tbytevector.cpp b/taglib/toolkit/tbytevector.cpp index 26444331..f8431ef0 100644 --- a/taglib/toolkit/tbytevector.cpp +++ b/taglib/toolkit/tbytevector.cpp @@ -95,7 +95,7 @@ namespace TagLib { template 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 diff --git a/tests/test_bytevector.cpp b/tests/test_bytevector.cpp index 56789fee..0a343e31 100644 --- a/tests/test_bytevector.cpp +++ b/tests/test_bytevector.cpp @@ -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));