mirror of https://github.com/aria2/aria2
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Used array_ptr for savedInfoHash, savedBitfield and pieceBitfield. * src/DefaultBtProgressInfoFile.ccpull/1/head
parent
a28f19befb
commit
5e835ae885
|
@ -1,3 +1,8 @@
|
||||||
|
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Used array_ptr for savedInfoHash, savedBitfield and pieceBitfield.
|
||||||
|
* src/DefaultBtProgressInfoFile.cc
|
||||||
|
|
||||||
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-06-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Throw an exception if position is less than 0.
|
Throw an exception if position is less than 0.
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
#include "a2io.h"
|
#include "a2io.h"
|
||||||
#include "DownloadFailureException.h"
|
#include "DownloadFailureException.h"
|
||||||
#include "StringFormat.h"
|
#include "StringFormat.h"
|
||||||
|
#include "array_fun.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -201,8 +202,6 @@ void DefaultBtProgressInfoFile::load()
|
||||||
{
|
{
|
||||||
_logger->info(MSG_LOADING_SEGMENT_FILE, _filename.c_str());
|
_logger->info(MSG_LOADING_SEGMENT_FILE, _filename.c_str());
|
||||||
std::ifstream in(_filename.c_str(), std::ios::in|std::ios::binary);
|
std::ifstream in(_filename.c_str(), std::ios::in|std::ios::binary);
|
||||||
unsigned char* savedInfoHash = 0;
|
|
||||||
unsigned char* savedBitfield = 0;
|
|
||||||
try {
|
try {
|
||||||
in.exceptions(std::ios::failbit);
|
in.exceptions(std::ios::failbit);
|
||||||
unsigned char versionBuf[2];
|
unsigned char versionBuf[2];
|
||||||
|
@ -238,8 +237,9 @@ void DefaultBtProgressInfoFile::load()
|
||||||
(StringFormat("Invalid info hash length: %d", infoHashLength).str());
|
(StringFormat("Invalid info hash length: %d", infoHashLength).str());
|
||||||
}
|
}
|
||||||
if(infoHashLength > 0) {
|
if(infoHashLength > 0) {
|
||||||
savedInfoHash = new unsigned char[infoHashLength];
|
array_ptr<unsigned char> savedInfoHash(new unsigned char[infoHashLength]);
|
||||||
in.read(reinterpret_cast<char*>(savedInfoHash), infoHashLength);
|
in.read(reinterpret_cast<char*>
|
||||||
|
(static_cast<unsigned char*>(savedInfoHash)), infoHashLength);
|
||||||
BtContextHandle btContext(dynamic_pointer_cast<BtContext>(_dctx));
|
BtContextHandle btContext(dynamic_pointer_cast<BtContext>(_dctx));
|
||||||
if(infoHashCheckEnabled &&
|
if(infoHashCheckEnabled &&
|
||||||
Util::toHex(savedInfoHash, infoHashLength) !=
|
Util::toHex(savedInfoHash, infoHashLength) !=
|
||||||
|
@ -250,8 +250,6 @@ void DefaultBtProgressInfoFile::load()
|
||||||
Util::toHex(savedInfoHash,
|
Util::toHex(savedInfoHash,
|
||||||
infoHashLength).c_str()).str());
|
infoHashLength).c_str()).str());
|
||||||
}
|
}
|
||||||
delete [] savedInfoHash;
|
|
||||||
savedInfoHash = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t pieceLength;
|
uint32_t pieceLength;
|
||||||
|
@ -296,13 +294,12 @@ void DefaultBtProgressInfoFile::load()
|
||||||
bitfieldLength).str());
|
bitfieldLength).str());
|
||||||
}
|
}
|
||||||
|
|
||||||
savedBitfield = new unsigned char[bitfieldLength];
|
array_ptr<unsigned char> savedBitfield(new unsigned char[bitfieldLength]);
|
||||||
in.read(reinterpret_cast<char*>(savedBitfield), bitfieldLength);
|
in.read(reinterpret_cast<char*>
|
||||||
|
(static_cast<unsigned char*>(savedBitfield)), bitfieldLength);
|
||||||
|
|
||||||
if(pieceLength == _dctx->getPieceLength()) {
|
if(pieceLength == _dctx->getPieceLength()) {
|
||||||
_pieceStorage->setBitfield(savedBitfield, bitfieldLength);
|
_pieceStorage->setBitfield(savedBitfield, bitfieldLength);
|
||||||
delete [] savedBitfield;
|
|
||||||
savedBitfield = 0;
|
|
||||||
|
|
||||||
uint32_t numInFlightPiece;
|
uint32_t numInFlightPiece;
|
||||||
in.read(reinterpret_cast<char*>(&numInFlightPiece),
|
in.read(reinterpret_cast<char*>(&numInFlightPiece),
|
||||||
|
@ -343,9 +340,11 @@ void DefaultBtProgressInfoFile::load()
|
||||||
" expected: %u actual: %u",
|
" expected: %u actual: %u",
|
||||||
piece->getBitfieldLength(), bitfieldLength).str());
|
piece->getBitfieldLength(), bitfieldLength).str());
|
||||||
}
|
}
|
||||||
savedBitfield = new unsigned char[bitfieldLength];
|
array_ptr<unsigned char> pieceBitfield
|
||||||
in.read(reinterpret_cast<char*>(savedBitfield), bitfieldLength);
|
(new unsigned char[bitfieldLength]);
|
||||||
piece->setBitfield(savedBitfield, bitfieldLength);
|
in.read(reinterpret_cast<char*>
|
||||||
|
(static_cast<unsigned char*>(pieceBitfield)), bitfieldLength);
|
||||||
|
piece->setBitfield(pieceBitfield, bitfieldLength);
|
||||||
|
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
|
|
||||||
|
@ -353,9 +352,6 @@ void DefaultBtProgressInfoFile::load()
|
||||||
|
|
||||||
#endif // ENABLE_MESSAGE_DIGEST
|
#endif // ENABLE_MESSAGE_DIGEST
|
||||||
|
|
||||||
delete [] savedBitfield;
|
|
||||||
savedBitfield = 0;
|
|
||||||
|
|
||||||
inFlightPieces.push_back(piece);
|
inFlightPieces.push_back(piece);
|
||||||
}
|
}
|
||||||
_pieceStorage->addInFlightPiece(inFlightPieces);
|
_pieceStorage->addInFlightPiece(inFlightPieces);
|
||||||
|
@ -378,13 +374,9 @@ void DefaultBtProgressInfoFile::load()
|
||||||
BitfieldMan dest(_dctx->getPieceLength(), totalLength);
|
BitfieldMan dest(_dctx->getPieceLength(), totalLength);
|
||||||
Util::convertBitfield(&dest, &src);
|
Util::convertBitfield(&dest, &src);
|
||||||
_pieceStorage->setBitfield(dest.getBitfield(), dest.getBitfieldLength());
|
_pieceStorage->setBitfield(dest.getBitfield(), dest.getBitfieldLength());
|
||||||
delete [] savedBitfield;
|
|
||||||
savedBitfield = 0;
|
|
||||||
}
|
}
|
||||||
_logger->info(MSG_LOADED_SEGMENT_FILE);
|
_logger->info(MSG_LOADED_SEGMENT_FILE);
|
||||||
} catch(std::ios::failure const& exception) {
|
} catch(std::ios::failure const& exception) {
|
||||||
delete [] savedBitfield;
|
|
||||||
delete [] savedInfoHash;
|
|
||||||
// TODO std::ios::failure doesn't give us the reasons of failure...
|
// TODO std::ios::failure doesn't give us the reasons of failure...
|
||||||
throw DL_ABORT_EX(StringFormat(EX_SEGMENT_FILE_READ,
|
throw DL_ABORT_EX(StringFormat(EX_SEGMENT_FILE_READ,
|
||||||
_filename.c_str(), strerror(errno)).str());
|
_filename.c_str(), strerror(errno)).str());
|
||||||
|
|
Loading…
Reference in New Issue