diff --git a/ChangeLog b/ChangeLog index c9e5bd1e..5671be13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-02-11 Tatsuhiro Tsujikawa + + Fixed the bug that adding 0 length filter to BitfieldMan filters 1 + block. It should not filter anything. + * src/BitfieldMan.cc + * src/ConsoleStatCalc.cc + * test/BitfieldManTest.cc + 2009-02-11 Tatsuhiro Tsujikawa Fixed the bug that the boolean options that don't take arguments diff --git a/src/BitfieldMan.cc b/src/BitfieldMan.cc index 7940bf25..7421b016 100644 --- a/src/BitfieldMan.cc +++ b/src/BitfieldMan.cc @@ -33,10 +33,12 @@ */ /* copyright --> */ #include "BitfieldMan.h" + +#include + #include "Randomizer.h" #include "Util.h" #include "array_fun.h" -#include namespace aria2 { @@ -609,10 +611,12 @@ void BitfieldMan::addFilter(uint64_t offset, uint64_t length) { filterBitfield = new unsigned char[bitfieldLength]; memset(filterBitfield, 0, bitfieldLength); } - size_t startBlock = offset/blockLength; - size_t endBlock = (offset+length-1)/blockLength; - for(size_t i = startBlock; i <= endBlock && i < blocks; i++) { - setFilterBit(i); + if(length > 0) { + size_t startBlock = offset/blockLength; + size_t endBlock = (offset+length-1)/blockLength; + for(size_t i = startBlock; i <= endBlock && i < blocks; i++) { + setFilterBit(i); + } } updateCache(); } diff --git a/src/ConsoleStatCalc.cc b/src/ConsoleStatCalc.cc index 89ba1d4e..cbd43984 100644 --- a/src/ConsoleStatCalc.cc +++ b/src/ConsoleStatCalc.cc @@ -75,10 +75,14 @@ static void printProgress(std::ostream& o, const SharedHandle& rg) #ifdef ENABLE_BITTORRENT if(rg->downloadFinished() && !dynamic_pointer_cast(rg->getDownloadContext()).isNull()) { - o << "SEEDING" << "(" << "ratio:" - << std::fixed << std::setprecision(1) - << ((stat.getAllTimeUploadLength()*10)/rg->getCompletedLength())/10.0 - << ")"; + o << "SEEDING" << "(" << "ratio:"; + if(rg->getCompletedLength() > 0) { + o << std::fixed << std::setprecision(1) + << ((stat.getAllTimeUploadLength()*10)/rg->getCompletedLength())/10.0; + } else { + o << "--"; + } + o << ")"; } else #endif // ENABLE_BITTORRENT { diff --git a/test/BitfieldManTest.cc b/test/BitfieldManTest.cc index c1539f9d..d7d6bf9c 100644 --- a/test/BitfieldManTest.cc +++ b/test/BitfieldManTest.cc @@ -1,8 +1,11 @@ #include "BitfieldMan.h" -#include "FixedNumberRandomizer.h" + #include + #include +#include "FixedNumberRandomizer.h" + namespace aria2 { class BitfieldManTest:public CppUnit::TestFixture { @@ -13,6 +16,7 @@ class BitfieldManTest:public CppUnit::TestFixture { CPPUNIT_TEST(testGetFirstMissingIndex); CPPUNIT_TEST(testIsAllBitSet); CPPUNIT_TEST(testFilter); + CPPUNIT_TEST(testAddFilter_zeroLength); CPPUNIT_TEST(testGetMissingIndex); CPPUNIT_TEST(testGetSparceMissingUnusedIndex); CPPUNIT_TEST(testGetSparceMissingUnusedIndex_setBit); @@ -54,6 +58,7 @@ public: void testIsAllBitSet(); void testFilter(); + void testAddFilter_zeroLength(); void testGetSparceMissingUnusedIndex(); void testGetSparceMissingUnusedIndex_setBit(); void testIsBitSetOffsetRange(); @@ -369,6 +374,15 @@ void BitfieldManTest::testFilter() { } +void BitfieldManTest::testAddFilter_zeroLength() +{ + BitfieldMan bits(1024, 1024*1024); + bits.addFilter(2048, 0); + bits.enableFilter(); + CPPUNIT_ASSERT_EQUAL((size_t)0, bits.countMissingBlock()); + CPPUNIT_ASSERT(bits.isFilteredAllBitSet()); +} + void BitfieldManTest::testGetMissingIndex() { BitfieldMan bt1(1024, 1024*256); bt1.setRandomizer(fixedNumberRandomizer);