From 538a8fcfe7d56e2d3bea25599d015df94ab9e7e6 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 15 Mar 2008 04:19:46 +0000 Subject: [PATCH] 2008-03-15 Tatsuhiro Tsujikawa Fixed compilation error with g++-4.3 --- ChangeLog | 4 +++ src/AbstractCommand.cc | 8 ++--- src/AbstractDiskWriter.cc | 1 + src/AlphaNumberDecorator.h | 1 + src/BinaryStream.h | 1 + src/BtConstants.h | 1 + src/BtKeepAliveMessage.cc | 1 + src/BtRequestMessage.cc | 2 +- src/Command.h | 1 + src/Cookie.cc | 4 +-- src/CookieParser.cc | 1 + src/DHTAutoSaveCommand.cc | 1 + src/DHTGetPeersCommand.cc | 2 +- src/DHTNode.cc | 5 +++ src/DHTNode.h | 5 +-- src/Data.cc | 1 + src/DefaultBtContext.cc | 5 +++ src/DefaultBtContext.h | 5 +-- src/DefaultBtProgressInfoFile.cc | 3 +- src/DefaultPeerStorage.cc | 4 +-- src/Dictionary.cc | 1 + src/DownloadCommand.cc | 4 +-- src/File.cc | 2 ++ src/FileAllocationIterator.h | 1 + src/HttpHeader.cc | 10 +++--- src/HttpRequest.cc | 10 +++--- src/IteratableValidator.h | 1 + src/MetaFileUtil.cc | 1 + src/MetalinkParserState.h | 1 + src/NameMatchOptionHandler.h | 1 + src/PeerAbstractCommand.cc | 4 +-- src/PeerConnection.h | 1 + src/PeerInteractionCommand.cc | 4 +-- src/ProgressAwareEntry.h | 1 + src/Request.cc | 2 +- src/RequestGroup.cc | 10 +++--- src/Segment.h | 1 + src/SegmentMan.cc | 1 + src/SimpleLogger.cc | 1 + src/SingleFileAllocationIterator.cc | 1 + src/SocketCore.h | 1 + src/UnknownLengthPieceStorage.cc | 28 +++++++++++++++++ src/UnknownLengthPieceStorage.h | 29 +++++------------ src/Util.cc | 48 +++++++++++++++++++++++------ src/Util.h | 4 ++- src/array_fun.h | 19 ++++++------ src/option_processing.cc | 1 + test/BNodeTest.cc | 1 + test/BitfieldManTest.cc | 1 + test/DHTBucketTest.cc | 2 ++ test/DHTIDCloserTest.cc | 1 + test/DHTMessageFactoryImplTest.cc | 1 + test/DHTUtilTest.cc | 1 + test/DefaultBtContextTest.cc | 1 + test/FixedNumberRandomizer.h | 1 + test/MockBtContext.h | 1 + test/MultiDiskAdaptorTest.cc | 6 ++-- test/UtilTest.cc | 22 +++++++++++++ 58 files changed, 196 insertions(+), 86 deletions(-) diff --git a/ChangeLog b/ChangeLog index e94ae4e2..b0c89c94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-03-15 Tatsuhiro Tsujikawa + + Fixed compilation error with g++-4.3 + 2008-03-13 Tatsuhiro Tsujikawa Added missing include files for MinGW diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index 9833ed10..8399d2af 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -110,12 +110,12 @@ bool AbstractCommand::execute() { return true; } } - if(checkSocketIsReadable && readCheckTarget->isReadable(0) || - checkSocketIsWritable && writeCheckTarget->isWritable(0) || + if((checkSocketIsReadable && readCheckTarget->isReadable(0)) || + (checkSocketIsWritable && writeCheckTarget->isWritable(0)) || #ifdef ENABLE_ASYNC_DNS - nameResolverCheck && nameResolveFinished() || + (nameResolverCheck && nameResolveFinished()) || #endif // ENABLE_ASYNC_DNS - !checkSocketIsReadable && !checkSocketIsWritable && !nameResolverCheck) { + (!checkSocketIsReadable && !checkSocketIsWritable && !nameResolverCheck)) { checkPoint.reset(); if(!_requestGroup->getPieceStorage().isNull()) { _segments = _requestGroup->getSegmentMan()->getInFlightSegment(cuid); diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index 74b9fec0..9b3914f4 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -41,6 +41,7 @@ #include "DlAbortEx.h" #include "a2io.h" #include +#include #include namespace aria2 { diff --git a/src/AlphaNumberDecorator.h b/src/AlphaNumberDecorator.h index 4e9c04a8..5a9cdad7 100644 --- a/src/AlphaNumberDecorator.h +++ b/src/AlphaNumberDecorator.h @@ -37,6 +37,7 @@ #include "NumberDecorator.h" #include "DlAbortEx.h" +#include namespace aria2 { diff --git a/src/BinaryStream.h b/src/BinaryStream.h index b0ba396a..9af8b3bf 100644 --- a/src/BinaryStream.h +++ b/src/BinaryStream.h @@ -37,6 +37,7 @@ #include "common.h" #include "SharedHandle.h" +#include namespace aria2 { diff --git a/src/BtConstants.h b/src/BtConstants.h index 57c45d28..10b932d4 100644 --- a/src/BtConstants.h +++ b/src/BtConstants.h @@ -37,6 +37,7 @@ #include "common.h" #include +#include typedef std::map Extensions; diff --git a/src/BtKeepAliveMessage.cc b/src/BtKeepAliveMessage.cc index f32c26c0..3b62669e 100644 --- a/src/BtKeepAliveMessage.cc +++ b/src/BtKeepAliveMessage.cc @@ -33,6 +33,7 @@ */ /* copyright --> */ #include "BtKeepAliveMessage.h" +#include namespace aria2 { diff --git a/src/BtRequestMessage.cc b/src/BtRequestMessage.cc index 37fedbc6..1b014d10 100644 --- a/src/BtRequestMessage.cc +++ b/src/BtRequestMessage.cc @@ -65,7 +65,7 @@ BtRequestMessageHandle BtRequestMessage::create(const unsigned char* data, size_ void BtRequestMessage::doReceivedAction() { if(pieceStorage->hasPiece(index) && (!peer->amChoking() || - peer->amChoking() && peer->isInAmAllowedIndexSet(index))) { + (peer->amChoking() && peer->isInAmAllowedIndexSet(index)))) { BtMessageHandle msg = messageFactory->createPieceMessage(index, begin, length); diff --git a/src/Command.h b/src/Command.h index 3d61a5c3..5e2e4e13 100644 --- a/src/Command.h +++ b/src/Command.h @@ -36,6 +36,7 @@ #define _D_COMMAND_H_ #include "common.h" +#include #include namespace aria2 { diff --git a/src/Cookie.cc b/src/Cookie.cc index 830d6faf..0f7a8834 100644 --- a/src/Cookie.cc +++ b/src/Cookie.cc @@ -86,10 +86,10 @@ bool Cookie::good() const bool Cookie::match(const std::string& host, const std::string& dir, time_t date, bool secure) const { - if((secure || !this->secure && !secure) && + if((secure || (!this->secure && !secure)) && Util::endsWith("."+host, this->domain) && Util::startsWith(dir, this->path) && - (this->onetime || date < this->expires)) { + (this->onetime || (date < this->expires))) { return true; } else { return false; diff --git a/src/CookieParser.cc b/src/CookieParser.cc index 950a381f..31678146 100644 --- a/src/CookieParser.cc +++ b/src/CookieParser.cc @@ -34,6 +34,7 @@ /* copyright --> */ #include "CookieParser.h" #include "Util.h" +#include #include #include diff --git a/src/DHTAutoSaveCommand.cc b/src/DHTAutoSaveCommand.cc index e6fe8641..90aaa390 100644 --- a/src/DHTAutoSaveCommand.cc +++ b/src/DHTAutoSaveCommand.cc @@ -48,6 +48,7 @@ #include "Logger.h" #include #include +#include namespace aria2 { diff --git a/src/DHTGetPeersCommand.cc b/src/DHTGetPeersCommand.cc index 07111ed7..56938a34 100644 --- a/src/DHTGetPeersCommand.cc +++ b/src/DHTGetPeersCommand.cc @@ -72,7 +72,7 @@ bool DHTGetPeersCommand::execute() return true; } if(_task.isNull() && - (_numRetry > 0 && _lastGetPeerTime.elapsed(RETRY_INTERVAL) || + ((_numRetry > 0 && _lastGetPeerTime.elapsed(RETRY_INTERVAL)) || _lastGetPeerTime.elapsed(GET_PEER_INTERVAL))) { logger->debug("Issuing PeerLookup for infoHash=%s", btContext->getInfoHashAsString().c_str()); diff --git a/src/DHTNode.cc b/src/DHTNode.cc index ee5a6af3..9c548001 100644 --- a/src/DHTNode.cc +++ b/src/DHTNode.cc @@ -116,4 +116,9 @@ std::string DHTNode::toString() const ", RTT="+Util::uitos(_rtt); } +void DHTNode::setID(const unsigned char* id) +{ + memcpy(_id, id, DHT_ID_LENGTH); +} + } // namespace aria2 diff --git a/src/DHTNode.h b/src/DHTNode.h index dcdc4c68..e4452a83 100644 --- a/src/DHTNode.h +++ b/src/DHTNode.h @@ -87,10 +87,7 @@ public: _ipaddr = ipaddr; } - void setID(const unsigned char* id) - { - memcpy(_id, id, DHT_ID_LENGTH); - } + void setID(const unsigned char* id); uint16_t getPort() const { diff --git a/src/Data.cc b/src/Data.cc index d0bef9d5..e1fdd356 100644 --- a/src/Data.cc +++ b/src/Data.cc @@ -35,6 +35,7 @@ #include "Data.h" #include "MetaEntryVisitor.h" #include +#include // <-- TODO remove this if strtoll is replaced with Util::parseLLInt() namespace aria2 { diff --git a/src/DefaultBtContext.cc b/src/DefaultBtContext.cc index 9d134f22..43499ac4 100644 --- a/src/DefaultBtContext.cc +++ b/src/DefaultBtContext.cc @@ -456,4 +456,9 @@ DefaultBtContext::getNodes() return _nodes; } +void DefaultBtContext::setInfoHash(const unsigned char* infoHash) +{ + memcpy(this->infoHash, infoHash, sizeof(this->infoHash)); +} + } // namespace aria2 diff --git a/src/DefaultBtContext.h b/src/DefaultBtContext.h index 42a25455..060e9f6d 100644 --- a/src/DefaultBtContext.h +++ b/src/DefaultBtContext.h @@ -160,10 +160,7 @@ private: } // for unit test - void setInfoHash(const unsigned char* infoHash) - { - memcpy(this->infoHash, infoHash, sizeof(this->infoHash)); - } + void setInfoHash(const unsigned char* infoHash); void setNumPieces(size_t numPieces) { diff --git a/src/DefaultBtProgressInfoFile.cc b/src/DefaultBtProgressInfoFile.cc index 85158e78..d5c3c939 100644 --- a/src/DefaultBtProgressInfoFile.cc +++ b/src/DefaultBtProgressInfoFile.cc @@ -53,6 +53,7 @@ #include "DownloadFailureException.h" #include #include +#include namespace aria2 { @@ -182,7 +183,7 @@ void DefaultBtProgressInfoFile::load() uint32_t infoHashLength; in.read(reinterpret_cast(&infoHashLength), sizeof(infoHashLength)); - if(infoHashLength < 0 || infoHashLength == 0 && infoHashCheckEnabled) { + if((infoHashLength < 0) || ((infoHashLength == 0) && infoHashCheckEnabled)) { throw new DlAbortEx("Invalid info hash length: %d", infoHashLength); } if(infoHashLength > 0) { diff --git a/src/DefaultPeerStorage.cc b/src/DefaultPeerStorage.cc index 8a09b8df..bc6a60af 100644 --- a/src/DefaultPeerStorage.cc +++ b/src/DefaultPeerStorage.cc @@ -66,8 +66,8 @@ public: FindIdenticalPeer(const PeerHandle& peer):_peer(peer) {} bool operator()(const PeerHandle& peer) const { - return _peer == peer || - _peer->ipaddr == peer->ipaddr && _peer->port == peer->port; + return (_peer == peer) || + ((_peer->ipaddr == peer->ipaddr) && (_peer->port == peer->port)); } }; diff --git a/src/Dictionary.cc b/src/Dictionary.cc index 81a4b484..16c785a2 100644 --- a/src/Dictionary.cc +++ b/src/Dictionary.cc @@ -34,6 +34,7 @@ /* copyright --> */ #include "Dictionary.h" #include "MetaEntryVisitor.h" +#include namespace aria2 { diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 4cc32d59..3e052266 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -142,8 +142,8 @@ bool DownloadCommand::executeInternal() { if(_requestGroup->getTotalLength() != 0 && bufSize == 0) { throw new DlRetryEx(EX_GOT_EOF); } - if(!transferDecoder.isNull() && transferDecoder->finished() - || transferDecoder.isNull() && segment->complete() + if((!transferDecoder.isNull() && transferDecoder->finished()) + || (transferDecoder.isNull() && segment->complete()) || bufSize == 0) { if(!transferDecoder.isNull()) transferDecoder->end(); logger->info(MSG_SEGMENT_DOWNLOAD_COMPLETED, cuid); diff --git a/src/File.cc b/src/File.cc index 7daa3dce..6af28fd0 100644 --- a/src/File.cc +++ b/src/File.cc @@ -34,10 +34,12 @@ /* copyright --> */ #include "File.h" #include "Util.h" +#define basename posix_basename #include // use GNU version basename #undef basename #include +#include #include namespace aria2 { diff --git a/src/FileAllocationIterator.h b/src/FileAllocationIterator.h index 474ecc70..9db182f0 100644 --- a/src/FileAllocationIterator.h +++ b/src/FileAllocationIterator.h @@ -37,6 +37,7 @@ #include "common.h" #include "SharedHandle.h" +#include namespace aria2 { diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index e855f670..4d514bf2 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -73,7 +73,7 @@ uint64_t HttpHeader::getFirstAsULLInt(const std::string& name) const { if(value == "") { return 0; } else { - return strtoull(value.c_str(), 0, 10); + return Util::parseULLInt(value); } } @@ -85,7 +85,7 @@ RangeHandle HttpHeader::getRange() const if(contentLengthStr == "") { return new Range(0, 0, 0); } else { - uint64_t contentLength = strtoull(contentLengthStr.c_str(), 0, 10); + uint64_t contentLength = Util::parseULLInt(contentLengthStr); if(contentLength == 0) { return new Range(0, 0, 0); } else { @@ -102,9 +102,9 @@ RangeHandle HttpHeader::getRange() const std::pair startEndBytePair; Util::split(startEndBytePair, rangePair.first, '-'); - uint64_t startByte = STRTOULL(startEndBytePair.first.c_str()); - uint64_t endByte = STRTOULL(startEndBytePair.second.c_str()); - uint64_t entityLength = STRTOULL(rangePair.second.c_str()); + off_t startByte = Util::parseLLInt(startEndBytePair.first); + off_t endByte = Util::parseLLInt(startEndBytePair.second); + uint64_t entityLength = Util::parseULLInt(rangePair.second); return new Range(startByte, endByte, entityLength); } diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index c756cf69..f1b0f8f3 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -115,11 +115,11 @@ bool HttpRequest::isRangeSatisfied(const RangeHandle& range) const if(segment.isNull()) { return true; } - if(getStartByte() == range->getStartByte() && - (getEndByte() == 0 || - getEndByte() > 0 && getEndByte() == range->getEndByte()) && - (entityLength == 0 || - entityLength > 0 && entityLength == range->getEntityLength())) { + if((getStartByte() == range->getStartByte()) && + ((getEndByte() == 0) || + ((getEndByte() > 0) && (getEndByte() == range->getEndByte()))) && + ((entityLength == 0) || + ((entityLength > 0) && (entityLength == range->getEntityLength())))) { return true; } else { return false; diff --git a/src/IteratableValidator.h b/src/IteratableValidator.h index 4737c39d..0db070ee 100644 --- a/src/IteratableValidator.h +++ b/src/IteratableValidator.h @@ -37,6 +37,7 @@ #include "common.h" #include "SharedHandle.h" +#include namespace aria2 { diff --git a/src/MetaFileUtil.cc b/src/MetaFileUtil.cc index a4e15b60..5133d33d 100644 --- a/src/MetaFileUtil.cc +++ b/src/MetaFileUtil.cc @@ -40,6 +40,7 @@ #include "DlAbortEx.h" #include "message.h" #include +#include // <-- TODO remove this if strtoul is replaced with Util::parseUInt() namespace aria2 { diff --git a/src/MetalinkParserState.h b/src/MetalinkParserState.h index 436758c2..59c69c00 100644 --- a/src/MetalinkParserState.h +++ b/src/MetalinkParserState.h @@ -37,6 +37,7 @@ #include "common.h" #include +#include namespace aria2 { diff --git a/src/NameMatchOptionHandler.h b/src/NameMatchOptionHandler.h index 5f4c1139..d8c0e099 100644 --- a/src/NameMatchOptionHandler.h +++ b/src/NameMatchOptionHandler.h @@ -37,6 +37,7 @@ #include "OptionHandler.h" #include "DlAbortEx.h" +#include namespace aria2 { diff --git a/src/PeerAbstractCommand.cc b/src/PeerAbstractCommand.cc index 0595954d..b46fdc31 100644 --- a/src/PeerAbstractCommand.cc +++ b/src/PeerAbstractCommand.cc @@ -83,8 +83,8 @@ bool PeerAbstractCommand::execute() { uploadLimitCheck && (uploadLimit == 0 || e->getUploadSpeed() <= uploadLimit*1024) || */ - checkSocketIsReadable && readCheckTarget->isReadable(0) || - checkSocketIsWritable && writeCheckTarget->isWritable(0)) { + (checkSocketIsReadable && readCheckTarget->isReadable(0)) || + (checkSocketIsWritable && writeCheckTarget->isWritable(0))) { checkPoint.reset(); } if(checkPoint.elapsed(timeout)) { diff --git a/src/PeerConnection.h b/src/PeerConnection.h index 664291f4..57e97c9f 100644 --- a/src/PeerConnection.h +++ b/src/PeerConnection.h @@ -37,6 +37,7 @@ #include "common.h" #include "SharedHandle.h" +#include namespace aria2 { diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index 8c7e3514..51a670ce 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -218,8 +218,8 @@ bool PeerInteractionCommand::executeInternal() { if(btInteractive->countReceivedMessageInIteration() > 0) { updateKeepAlive(); } - if(peer->amInterested() && !peer->peerChoking() && peer->getLatency() < 1500 || - peer->peerInterested() && !peer->amChoking()) { + if((peer->amInterested() && !peer->peerChoking() && (peer->getLatency() < 1500)) || + (peer->peerInterested() && !peer->amChoking())) { if(maxDownloadSpeedLimit > 0) { TransferStat stat = peerStorage->calculateStat(); if(maxDownloadSpeedLimit < stat.downloadSpeed) { diff --git a/src/ProgressAwareEntry.h b/src/ProgressAwareEntry.h index 94383ef5..2915e254 100644 --- a/src/ProgressAwareEntry.h +++ b/src/ProgressAwareEntry.h @@ -38,6 +38,7 @@ #include "common.h" #include "SharedHandle.h" #include +#include namespace aria2 { diff --git a/src/Request.cc b/src/Request.cc index 0ad8674d..f9b2a5bb 100644 --- a/src/Request.cc +++ b/src/Request.cc @@ -154,7 +154,7 @@ bool Request::parseUrl(const std::string& url) { bool Request::isHexNumber(const char c) const { - return '0' <= c && c <= '9' || 'A' <= c && c <= 'F' || 'a' <= c && c <= 'f'; + return ('0' <= c && c <= '9') || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f'); } std::string Request::urlencode(const std::string& src) const diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc index 9ea0e284..a0cea123 100644 --- a/src/RequestGroup.cc +++ b/src/RequestGroup.cc @@ -321,9 +321,9 @@ bool RequestGroup::downloadFinishedByFileLength() { // assuming that a control file doesn't exist. if(!isPreLocalFileCheckEnabled() || - _option->get(PREF_ALLOW_OVERWRITE) == V_TRUE || - _option->get(PREF_CHECK_INTEGRITY) == V_TRUE && - !_downloadContext->getPieceHashes().empty()) { + (_option->get(PREF_ALLOW_OVERWRITE) == V_TRUE) || + ((_option->get(PREF_CHECK_INTEGRITY) == V_TRUE) && + !_downloadContext->getPieceHashes().empty())) { return false; } // TODO consider the case when the getFilePath() returns dir path. @@ -882,8 +882,8 @@ void RequestGroup::removeURIWhoseHostnameIs(const std::string& hostname) std::deque newURIs; Request req; for(std::deque::const_iterator itr = _uris.begin(); itr != _uris.end(); ++itr) { - if((*itr).find(hostname) == std::string::npos || - req.setUrl(*itr) && req.getHost() != hostname) { + if(((*itr).find(hostname) == std::string::npos) || + (req.setUrl(*itr) && (req.getHost() != hostname))) { newURIs.push_back(*itr); } } diff --git a/src/Segment.h b/src/Segment.h index c7499fbb..2e732236 100644 --- a/src/Segment.h +++ b/src/Segment.h @@ -37,6 +37,7 @@ #include "common.h" #include "SharedHandle.h" +#include #include #include diff --git a/src/SegmentMan.cc b/src/SegmentMan.cc index 084b4bc3..0f99628c 100644 --- a/src/SegmentMan.cc +++ b/src/SegmentMan.cc @@ -45,6 +45,7 @@ #include "Option.h" #include "DownloadContext.h" #include "Piece.h" +#include namespace aria2 { diff --git a/src/SimpleLogger.cc b/src/SimpleLogger.cc index f3a7ceb0..3b5b91ee 100644 --- a/src/SimpleLogger.cc +++ b/src/SimpleLogger.cc @@ -40,6 +40,7 @@ #include "a2time.h" #include #include +#include namespace aria2 { diff --git a/src/SingleFileAllocationIterator.cc b/src/SingleFileAllocationIterator.cc index c6660bd8..b7f87689 100644 --- a/src/SingleFileAllocationIterator.cc +++ b/src/SingleFileAllocationIterator.cc @@ -36,6 +36,7 @@ #include "BinaryStream.h" #include "Util.h" #include "a2io.h" +#include namespace aria2 { diff --git a/src/SocketCore.h b/src/SocketCore.h index 4fd53a81..e7222538 100644 --- a/src/SocketCore.h +++ b/src/SocketCore.h @@ -38,6 +38,7 @@ #include "common.h" #include "a2netcompat.h" #include "a2time.h" +#include #include #include diff --git a/src/UnknownLengthPieceStorage.cc b/src/UnknownLengthPieceStorage.cc index 3c35eeb7..f74d7544 100644 --- a/src/UnknownLengthPieceStorage.cc +++ b/src/UnknownLengthPieceStorage.cc @@ -40,6 +40,7 @@ #include "DownloadContext.h" #include "Piece.h" #include "FileEntry.h" +#include namespace aria2 { @@ -70,6 +71,21 @@ void UnknownLengthPieceStorage::initStorage() _diskAdaptor->setFileEntries(_downloadContext->getFileEntries()); } +bool UnknownLengthPieceStorage::hasMissingPiece(const SharedHandle& peer) +{ + abort(); +} + +SharedHandle UnknownLengthPieceStorage::getMissingPiece(const SharedHandle& peer) +{ + abort(); +} + +SharedHandle UnknownLengthPieceStorage::getMissingFastPiece(const SharedHandle& peer) +{ + abort(); +} + PieceHandle UnknownLengthPieceStorage::getMissingPiece() { if(_downloadFinished) { @@ -163,6 +179,18 @@ void UnknownLengthPieceStorage::markAllPiecesDone() _downloadFinished = true; } +void UnknownLengthPieceStorage::markPiecesDone(uint64_t length) +{ + // TODO not implemented yet + abort(); +} + +void UnknownLengthPieceStorage::markPieceMissing(size_t index) +{ + // TODO not implemented yet + abort(); +} + Pieces UnknownLengthPieceStorage::getInFlightPieces() { return Pieces(); diff --git a/src/UnknownLengthPieceStorage.h b/src/UnknownLengthPieceStorage.h index a1e61c3a..460faa66 100644 --- a/src/UnknownLengthPieceStorage.h +++ b/src/UnknownLengthPieceStorage.h @@ -69,10 +69,7 @@ public: * Returns true if the peer has a piece that localhost doesn't have. * Otherwise returns false. */ - virtual bool hasMissingPiece(const SharedHandle& peer) - { - abort(); - } + virtual bool hasMissingPiece(const SharedHandle& peer); /** * Returns a piece that the peer has but localhost doesn't. @@ -80,10 +77,8 @@ public: * from get the same piece. But in end game mode, same piece may be returned * to several commands. */ - virtual SharedHandle getMissingPiece(const SharedHandle& peer) - { - abort(); - } + virtual SharedHandle getMissingPiece(const SharedHandle& peer); + /** * Returns a piece that the peer has but localhost doesn't. * Only pieces that declared as "fast" are returned. @@ -91,10 +86,8 @@ public: * from get the same piece. But in end game mode, same piece may be returned * to several commands. */ - virtual SharedHandle getMissingFastPiece(const SharedHandle& peer) - { - abort(); - } + virtual SharedHandle getMissingFastPiece(const SharedHandle& peer); + /** * Returns a missing piece if available. Otherwise returns 0; */ @@ -240,17 +233,9 @@ public: */ virtual void markAllPiecesDone(); - virtual void markPiecesDone(uint64_t length) - { - // TODO not implemented yet - abort(); - } + virtual void markPiecesDone(uint64_t length); - virtual void markPieceMissing(size_t index) - { - // TODO not implemented yet - abort(); - } + virtual void markPieceMissing(size_t index); /** * Do nothing because loading in-flight piece is not supported for this diff --git a/src/Util.cc b/src/Util.cc index 9d532270..c137704a 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -100,7 +100,8 @@ std::pair Util::split(const std::string& src, const st } int64_t Util::difftv(struct timeval tv1, struct timeval tv2) { - if(tv1.tv_sec < tv2.tv_sec || tv1.tv_sec == tv2.tv_sec && tv1.tv_usec < tv2.tv_usec) { + if((tv1.tv_sec < tv2.tv_sec) || + ((tv1.tv_sec == tv2.tv_sec) && (tv1.tv_usec < tv2.tv_usec))) { return 0; } return ((int64_t)(tv1.tv_sec-tv2.tv_sec)*1000000+ @@ -187,9 +188,9 @@ std::string Util::replace(const std::string& target, const std::string& oldstr, bool Util::shouldUrlencode(const char c) { return !(// ALPHA - 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z' || + ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || // DIGIT - '0' <= c && c <= '9' || + ('0' <= c && c <= '9') || // safe '$' == c || '-' == c || '_' == c || '.' == c || // extra @@ -218,9 +219,9 @@ std::string Util::urlencode(const unsigned char* target, size_t len) { std::string Util::torrentUrlencode(const unsigned char* target, size_t len) { std::string dest; for(size_t i = 0; i < len; i++) { - if('0' <= target[i] && target[i] <= '9' || - 'A' <= target[i] && target[i] <= 'Z' || - 'a' <= target[i] && target[i] <= 'z') { + if(('0' <= target[i] && target[i] <= '9') || + ('A' <= target[i] && target[i] <= 'Z') || + ('a' <= target[i] && target[i] <= 'z')) { dest += target[i]; } else { char temp[4]; @@ -409,7 +410,9 @@ int32_t Util::parseInt(const std::string& s, int32_t base) if(*stop != '\0') { throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE, trimed.c_str()); - } else if((v == LONG_MIN || v == LONG_MAX) && errno == ERANGE || v > INT32_MAX || v < INT32_MIN) { + } else if((((v == LONG_MIN) || (v == LONG_MAX)) && (errno == ERANGE)) || + (v > INT32_MAX) || + (v < INT32_MIN)) { throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE, trimed.c_str()); } @@ -434,7 +437,7 @@ uint32_t Util::parseUInt(const std::string& s, int base) if(*stop != '\0') { throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE, trimed.c_str()); - } else if((v == ULONG_MAX) && errno == ERANGE || v > UINT32_MAX) { + } else if(((v == ULONG_MAX) && (errno == ERANGE)) || (v > UINT32_MAX)) { throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE, trimed.c_str()); } @@ -454,7 +457,32 @@ int64_t Util::parseLLInt(const std::string& s, int32_t base) if(*stop != '\0') { throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE, trimed.c_str()); - } else if((v == INT64_MIN || v == INT64_MAX) && errno == ERANGE) { + } else if(((v == INT64_MIN) || (v == INT64_MAX)) && (errno == ERANGE)) { + throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE, + trimed.c_str()); + } + return v; +} + +uint64_t Util::parseULLInt(const std::string& s, int base) +{ + std::string trimed = Util::trim(s); + if(trimed.empty()) { + throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE, + "empty string"); + } + // We don't allow negative number. + if(trimed[0] == '-') { + throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE, + trimed.c_str()); + } + char* stop; + errno = 0; + uint64_t v = strtoull(trimed.c_str(), &stop, base); + if(*stop != '\0') { + throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE, + trimed.c_str()); + } else if((v == ULLONG_MAX) && (errno == ERANGE)) { throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE, trimed.c_str()); } @@ -621,7 +649,7 @@ int64_t Util::getRealSize(const std::string& sizeWithUnit) if(v < 0) { throw new DlAbortEx("Negative value detected: %s", sizeWithUnit.c_str()); - } else if(v*mult < 0) { + } else if(INT64_MAX/mult < v) { throw new DlAbortEx(MSG_STRING_INTEGER_CONVERSION_FAILURE, "overflow/underflow"); } diff --git a/src/Util.h b/src/Util.h index 00588531..a9422575 100644 --- a/src/Util.h +++ b/src/Util.h @@ -168,10 +168,12 @@ public: static int32_t parseInt(const std::string& s, int32_t base = 10); - static unsigned int parseUInt(const std::string& s, int base = 10); + static uint32_t parseUInt(const std::string& s, int base = 10); static int64_t parseLLInt(const std::string& s, int32_t base = 10); + static uint64_t parseULLInt(const std::string& s, int base = 10); + static IntSequence parseIntRange(const std::string& src); // this function temporarily put here diff --git a/src/array_fun.h b/src/array_fun.h index 3647b6d8..ccf837a0 100644 --- a/src/array_fun.h +++ b/src/array_fun.h @@ -35,6 +35,7 @@ #ifndef _D_ARRAY_FUN_H_ #define _D_ARRAY_FUN_H_ +#include #include namespace aria2 { @@ -62,7 +63,7 @@ class array_function_base { public: virtual ~array_function_base() {} - virtual R operator[](std::size_t index) const = 0; + virtual R operator[](size_t index) const = 0; virtual array_function_base* clone() const = 0; }; @@ -75,7 +76,7 @@ private: public: array_unary_function(A a, F f):_a(a), _f(f) {} - virtual typename F::result_type operator[](std::size_t index) const + virtual typename F::result_type operator[](size_t index) const { return _f(_a[index]); } @@ -95,7 +96,7 @@ private: public: array_binary_function(A a, B b, F f):_a(a), _b(b), _f(f) {} - virtual typename F::result_type operator[](std::size_t index) const + virtual typename F::result_type operator[](size_t index) const { return _f(_a[index], _b[index]); } @@ -133,7 +134,7 @@ public: return *this; } - R operator[](std::size_t index) const + R operator[](size_t index) const { return (*_p)[index]; } @@ -199,19 +200,17 @@ array_and(A a, B b) // calculate length of array -template +template char (&char_array_ref(T (&)[N]))[N]; -template -std::size_t -arrayLength(T (&a)[N]) +template +size_t arrayLength(T (&a)[N]) { return sizeof(char_array_ref(a)); } template -std::size_t -arrayLength(T (&a)[0u]) +size_t arrayLength(T (&a)[0u]) { return 0; } diff --git a/src/option_processing.cc b/src/option_processing.cc index 296a7cdd..6c11cac1 100644 --- a/src/option_processing.cc +++ b/src/option_processing.cc @@ -44,6 +44,7 @@ #include "a2io.h" #include "help_tags.h" #include "File.h" +#include #include #include #include diff --git a/test/BNodeTest.cc b/test/BNodeTest.cc index 88d88d06..8aafa639 100644 --- a/test/BNodeTest.cc +++ b/test/BNodeTest.cc @@ -4,6 +4,7 @@ #include "DHTUtil.h" #include "Exception.h" #include "Util.h" +#include #include namespace aria2 { diff --git a/test/BitfieldManTest.cc b/test/BitfieldManTest.cc index 3012b1e0..cc46f7c6 100644 --- a/test/BitfieldManTest.cc +++ b/test/BitfieldManTest.cc @@ -1,5 +1,6 @@ #include "BitfieldMan.h" #include "FixedNumberRandomizer.h" +#include #include namespace aria2 { diff --git a/test/DHTBucketTest.cc b/test/DHTBucketTest.cc index f97eb17a..73f54e85 100644 --- a/test/DHTBucketTest.cc +++ b/test/DHTBucketTest.cc @@ -2,6 +2,8 @@ #include "DHTNode.h" #include "Exception.h" #include "Util.h" +#include +#include #include namespace aria2 { diff --git a/test/DHTIDCloserTest.cc b/test/DHTIDCloserTest.cc index f470901b..ebe51a5e 100644 --- a/test/DHTIDCloserTest.cc +++ b/test/DHTIDCloserTest.cc @@ -3,6 +3,7 @@ #include "DHTIDCloser.h" #include "Exception.h" #include "Util.h" +#include #include #include diff --git a/test/DHTMessageFactoryImplTest.cc b/test/DHTMessageFactoryImplTest.cc index 868836ac..7be1de95 100644 --- a/test/DHTMessageFactoryImplTest.cc +++ b/test/DHTMessageFactoryImplTest.cc @@ -17,6 +17,7 @@ #include "DHTGetPeersReplyMessage.h" #include "DHTAnnouncePeerMessage.h" #include "DHTAnnouncePeerReplyMessage.h" +#include #include #include diff --git a/test/DHTUtilTest.cc b/test/DHTUtilTest.cc index 28137735..ee9c0ad0 100644 --- a/test/DHTUtilTest.cc +++ b/test/DHTUtilTest.cc @@ -1,6 +1,7 @@ #include "DHTUtil.h" #include "Exception.h" #include "Util.h" +#include #include namespace aria2 { diff --git a/test/DefaultBtContextTest.cc b/test/DefaultBtContextTest.cc index 983e22e1..fa1f24e6 100644 --- a/test/DefaultBtContextTest.cc +++ b/test/DefaultBtContextTest.cc @@ -4,6 +4,7 @@ #include "AnnounceTier.h" #include "FixedNumberRandomizer.h" #include "FileEntry.h" +#include #include #include diff --git a/test/FixedNumberRandomizer.h b/test/FixedNumberRandomizer.h index c53975c2..dacaad99 100644 --- a/test/FixedNumberRandomizer.h +++ b/test/FixedNumberRandomizer.h @@ -2,6 +2,7 @@ #define _D_FIXED_NUMBER_RANDOMIZER_H_ #include "Randomizer.h" +#include namespace aria2 { diff --git a/test/MockBtContext.h b/test/MockBtContext.h index 9f143dc6..9373e991 100644 --- a/test/MockBtContext.h +++ b/test/MockBtContext.h @@ -4,6 +4,7 @@ #include "BtContext.h" #include "Util.h" #include "AnnounceTier.h" +#include namespace aria2 { diff --git a/test/MultiDiskAdaptorTest.cc b/test/MultiDiskAdaptorTest.cc index fd1d9ed8..63d70e83 100644 --- a/test/MultiDiskAdaptorTest.cc +++ b/test/MultiDiskAdaptorTest.cc @@ -2,6 +2,8 @@ #include "FileEntry.h" #include "Exception.h" #include +#include +#include #include namespace aria2 { @@ -48,12 +50,12 @@ std::deque > createEntries() { void readFile(const std::string& filename, char* buf, int bufLength) { FILE* f = fopen(filename.c_str(), "r"); if(f == NULL) { - abort(); + CPPUNIT_FAIL(strerror(errno)); } int retval = fread(buf, bufLength, 1, f); fclose(f); if(retval != 1) { - abort(); + CPPUNIT_FAIL("return value is not 1"); } } diff --git a/test/UtilTest.cc b/test/UtilTest.cc index 5b38b58c..8e760375 100644 --- a/test/UtilTest.cc +++ b/test/UtilTest.cc @@ -41,6 +41,7 @@ class UtilTest:public CppUnit::TestFixture { CPPUNIT_TEST(testParseInt); CPPUNIT_TEST(testParseUInt); CPPUNIT_TEST(testParseLLInt); + CPPUNIT_TEST(testParseULLInt); CPPUNIT_TEST(testToString_binaryStream); CPPUNIT_TEST(testItos); CPPUNIT_TEST(testUitos); @@ -78,6 +79,7 @@ public: void testParseInt(); void testParseUInt(); void testParseLLInt(); + void testParseULLInt(); void testToString_binaryStream(); void testItos(); void testUitos(); @@ -612,6 +614,26 @@ void UtilTest::testParseLLInt() } } +void UtilTest::testParseULLInt() +{ + CPPUNIT_ASSERT_EQUAL(18446744073709551615ULL, + Util::parseULLInt("18446744073709551615")); + try { + Util::parseUInt("-1"); + CPPUNIT_FAIL("exception must be thrown."); + } catch(Exception* e) { + std::cerr << *e; + delete e; + } + try { + Util::parseLLInt("18446744073709551616"); + CPPUNIT_FAIL("exception must be thrown."); + } catch(Exception* e) { + std::cerr << *e; + delete e; + } +} + void UtilTest::testToString_binaryStream() { SharedHandle dw = new ByteArrayDiskWriter();