From 7e90313690e716a0c761436aacde72cafb3f7d45 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kevin=20Andr=C3=A9?= Date: Thu, 15 Sep 2016 16:30:16 +0200 Subject: [PATCH] Fix defect in ByteVectorStream::seek when Position==End. --- taglib/toolkit/tbytevectorstream.cpp | 2 +- tests/test_bytevectorstream.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/taglib/toolkit/tbytevectorstream.cpp b/taglib/toolkit/tbytevectorstream.cpp index 5e200b3d..74b2eced 100644 --- a/taglib/toolkit/tbytevectorstream.cpp +++ b/taglib/toolkit/tbytevectorstream.cpp @@ -137,7 +137,7 @@ void ByteVectorStream::seek(long offset, Position p) d->position += offset; break; case End: - d->position = length() - offset; + d->position = length() + offset; // offset is expected to be negative break; } } diff --git a/tests/test_bytevectorstream.cpp b/tests/test_bytevectorstream.cpp index c7b0f105..f8308c6d 100644 --- a/tests/test_bytevectorstream.cpp +++ b/tests/test_bytevectorstream.cpp @@ -38,6 +38,7 @@ class TestByteVectorStream : public CppUnit::TestFixture CPPUNIT_TEST(testReadBlock); CPPUNIT_TEST(testRemoveBlock); CPPUNIT_TEST(testInsert); + CPPUNIT_TEST(testSeekEnd); CPPUNIT_TEST_SUITE_END(); public: @@ -112,6 +113,19 @@ public: CPPUNIT_ASSERT_EQUAL(ByteVector("yyx123foa"), *stream.data()); } + void testSeekEnd() + { + ByteVector v("abcdefghijklmnopqrstuvwxyz"); + ByteVectorStream stream(v); + CPPUNIT_ASSERT_EQUAL(26L, stream.length()); + + stream.seek(-4, IOStream::End); + CPPUNIT_ASSERT_EQUAL(ByteVector("w"), stream.readBlock(1)); + + stream.seek(-25, IOStream::End); + CPPUNIT_ASSERT_EQUAL(ByteVector("b"), stream.readBlock(1)); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestByteVectorStream); -- 2.40.0