Browse Source

2008-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Fixed compilation error with g++-4.3
Tatsuhiro Tsujikawa 17 years ago
parent
commit
538a8fcfe7
58 changed files with 196 additions and 86 deletions
  1. 4 0
      ChangeLog
  2. 4 4
      src/AbstractCommand.cc
  3. 1 0
      src/AbstractDiskWriter.cc
  4. 1 0
      src/AlphaNumberDecorator.h
  5. 1 0
      src/BinaryStream.h
  6. 1 0
      src/BtConstants.h
  7. 1 0
      src/BtKeepAliveMessage.cc
  8. 1 1
      src/BtRequestMessage.cc
  9. 1 0
      src/Command.h
  10. 2 2
      src/Cookie.cc
  11. 1 0
      src/CookieParser.cc
  12. 1 0
      src/DHTAutoSaveCommand.cc
  13. 1 1
      src/DHTGetPeersCommand.cc
  14. 5 0
      src/DHTNode.cc
  15. 1 4
      src/DHTNode.h
  16. 1 0
      src/Data.cc
  17. 5 0
      src/DefaultBtContext.cc
  18. 1 4
      src/DefaultBtContext.h
  19. 2 1
      src/DefaultBtProgressInfoFile.cc
  20. 2 2
      src/DefaultPeerStorage.cc
  21. 1 0
      src/Dictionary.cc
  22. 2 2
      src/DownloadCommand.cc
  23. 2 0
      src/File.cc
  24. 1 0
      src/FileAllocationIterator.h
  25. 5 5
      src/HttpHeader.cc
  26. 5 5
      src/HttpRequest.cc
  27. 1 0
      src/IteratableValidator.h
  28. 1 0
      src/MetaFileUtil.cc
  29. 1 0
      src/MetalinkParserState.h
  30. 1 0
      src/NameMatchOptionHandler.h
  31. 2 2
      src/PeerAbstractCommand.cc
  32. 1 0
      src/PeerConnection.h
  33. 2 2
      src/PeerInteractionCommand.cc
  34. 1 0
      src/ProgressAwareEntry.h
  35. 1 1
      src/Request.cc
  36. 5 5
      src/RequestGroup.cc
  37. 1 0
      src/Segment.h
  38. 1 0
      src/SegmentMan.cc
  39. 1 0
      src/SimpleLogger.cc
  40. 1 0
      src/SingleFileAllocationIterator.cc
  41. 1 0
      src/SocketCore.h
  42. 28 0
      src/UnknownLengthPieceStorage.cc
  43. 7 22
      src/UnknownLengthPieceStorage.h
  44. 38 10
      src/Util.cc
  45. 3 1
      src/Util.h
  46. 9 10
      src/array_fun.h
  47. 1 0
      src/option_processing.cc
  48. 1 0
      test/BNodeTest.cc
  49. 1 0
      test/BitfieldManTest.cc
  50. 2 0
      test/DHTBucketTest.cc
  51. 1 0
      test/DHTIDCloserTest.cc
  52. 1 0
      test/DHTMessageFactoryImplTest.cc
  53. 1 0
      test/DHTUtilTest.cc
  54. 1 0
      test/DefaultBtContextTest.cc
  55. 1 0
      test/FixedNumberRandomizer.h
  56. 1 0
      test/MockBtContext.h
  57. 4 2
      test/MultiDiskAdaptorTest.cc
  58. 22 0
      test/UtilTest.cc

+ 4 - 0
ChangeLog

@@ -1,3 +1,7 @@
+2008-03-15  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Fixed compilation error with g++-4.3
+
 2008-03-13  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Added missing include files for MinGW

+ 4 - 4
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);

+ 1 - 0
src/AbstractDiskWriter.cc

@@ -41,6 +41,7 @@
 #include "DlAbortEx.h"
 #include "a2io.h"
 #include <cerrno>
+#include <cstring>
 #include <cassert>
 
 namespace aria2 {

+ 1 - 0
src/AlphaNumberDecorator.h

@@ -37,6 +37,7 @@
 
 #include "NumberDecorator.h"
 #include "DlAbortEx.h"
+#include <algorithm>
 
 namespace aria2 {
 

+ 1 - 0
src/BinaryStream.h

@@ -37,6 +37,7 @@
 
 #include "common.h"
 #include "SharedHandle.h"
+#include <unistd.h>
 
 namespace aria2 {
 

+ 1 - 0
src/BtConstants.h

@@ -37,6 +37,7 @@
 
 #include "common.h"
 #include <map>
+#include <string>
 
 typedef std::map<std::string, uint8_t> Extensions;
 

+ 1 - 0
src/BtKeepAliveMessage.cc

@@ -33,6 +33,7 @@
  */
 /* copyright --> */
 #include "BtKeepAliveMessage.h"
+#include <cstring>
 
 namespace aria2 {
 

+ 1 - 1
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);

+ 1 - 0
src/Command.h

@@ -36,6 +36,7 @@
 #define _D_COMMAND_H_
 
 #include "common.h"
+#include <stdint.h>
 #include <deque>
 
 namespace aria2 {

+ 2 - 2
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;

+ 1 - 0
src/CookieParser.cc

@@ -34,6 +34,7 @@
 /* copyright --> */
 #include "CookieParser.h"
 #include "Util.h"
+#include <strings.h>
 #include <utility>
 #include <istream>
 

+ 1 - 0
src/DHTAutoSaveCommand.cc

@@ -48,6 +48,7 @@
 #include "Logger.h"
 #include <cerrno>
 #include <fstream>
+#include <cstring>
 
 namespace aria2 {
 

+ 1 - 1
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());

+ 5 - 0
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

+ 1 - 4
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
   {

+ 1 - 0
src/Data.cc

@@ -35,6 +35,7 @@
 #include "Data.h"
 #include "MetaEntryVisitor.h"
 #include <cstring>
+#include <cstdlib> // <-- TODO remove this if strtoll is replaced with Util::parseLLInt()
 
 namespace aria2 {
 

+ 5 - 0
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

+ 1 - 4
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)
   {

+ 2 - 1
src/DefaultBtProgressInfoFile.cc

@@ -53,6 +53,7 @@
 #include "DownloadFailureException.h"
 #include <fstream>
 #include <cerrno>
+#include <cstring>
 
 namespace aria2 {
 
@@ -182,7 +183,7 @@ void DefaultBtProgressInfoFile::load()
 
     uint32_t infoHashLength;
     in.read(reinterpret_cast<char*>(&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) {

+ 2 - 2
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));
   }
 };
 

+ 1 - 0
src/Dictionary.cc

@@ -34,6 +34,7 @@
 /* copyright --> */
 #include "Dictionary.h"
 #include "MetaEntryVisitor.h"
+#include <algorithm>
 
 namespace aria2 {
 

+ 2 - 2
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);

+ 2 - 0
src/File.cc

@@ -34,10 +34,12 @@
 /* copyright --> */
 #include "File.h"
 #include "Util.h"
+#define basename posix_basename
 #include <libgen.h>
 // use GNU version basename
 #undef basename
 #include <cstring>
+#include <stdlib.h>
 #include <deque>
 
 namespace aria2 {

+ 1 - 0
src/FileAllocationIterator.h

@@ -37,6 +37,7 @@
 
 #include "common.h"
 #include "SharedHandle.h"
+#include <unistd.h>
 
 namespace aria2 {
 

+ 5 - 5
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<std::string, std::string> 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);
 }

+ 5 - 5
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;

+ 1 - 0
src/IteratableValidator.h

@@ -37,6 +37,7 @@
 
 #include "common.h"
 #include "SharedHandle.h"
+#include <unistd.h>
 
 namespace aria2 {
 

+ 1 - 0
src/MetaFileUtil.cc

@@ -40,6 +40,7 @@
 #include "DlAbortEx.h"
 #include "message.h"
 #include <cstring>
+#include <cstdlib> // <-- TODO remove this if strtoul is replaced with Util::parseUInt()
 
 namespace aria2 {
 

+ 1 - 0
src/MetalinkParserState.h

@@ -37,6 +37,7 @@
 
 #include "common.h"
 #include <map>
+#include <string>
 
 namespace aria2 {
 

+ 1 - 0
src/NameMatchOptionHandler.h

@@ -37,6 +37,7 @@
 
 #include "OptionHandler.h"
 #include "DlAbortEx.h"
+#include <strings.h>
 
 namespace aria2 {
 

+ 2 - 2
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)) {

+ 1 - 0
src/PeerConnection.h

@@ -37,6 +37,7 @@
 
 #include "common.h"
 #include "SharedHandle.h"
+#include <unistd.h>
 
 namespace aria2 {
 

+ 2 - 2
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) {

+ 1 - 0
src/ProgressAwareEntry.h

@@ -38,6 +38,7 @@
 #include "common.h"
 #include "SharedHandle.h"
 #include <stdint.h>
+#include <unistd.h>
 
 namespace aria2 {
 

+ 1 - 1
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

+ 5 - 5
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<std::string> newURIs;
   Request req;
   for(std::deque<std::string>::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);
     }
   }

+ 1 - 0
src/Segment.h

@@ -37,6 +37,7 @@
 
 #include "common.h"
 #include "SharedHandle.h"
+#include <unistd.h>
 #include <stdint.h>
 #include <deque>
 

+ 1 - 0
src/SegmentMan.cc

@@ -45,6 +45,7 @@
 #include "Option.h"
 #include "DownloadContext.h"
 #include "Piece.h"
+#include <algorithm>
 
 namespace aria2 {
 

+ 1 - 0
src/SimpleLogger.cc

@@ -40,6 +40,7 @@
 #include "a2time.h"
 #include <cstdarg>
 #include <cerrno>
+#include <cstring>
 
 namespace aria2 {
 

+ 1 - 0
src/SingleFileAllocationIterator.cc

@@ -36,6 +36,7 @@
 #include "BinaryStream.h"
 #include "Util.h"
 #include "a2io.h"
+#include <cstring>
 
 namespace aria2 {
 

+ 1 - 0
src/SocketCore.h

@@ -38,6 +38,7 @@
 #include "common.h"
 #include "a2netcompat.h"
 #include "a2time.h"
+#include <cstdlib>
 #include <string>
 #include <utility>
 

+ 28 - 0
src/UnknownLengthPieceStorage.cc

@@ -40,6 +40,7 @@
 #include "DownloadContext.h"
 #include "Piece.h"
 #include "FileEntry.h"
+#include <stdlib.h>
 
 namespace aria2 {
 
@@ -70,6 +71,21 @@ void UnknownLengthPieceStorage::initStorage()
   _diskAdaptor->setFileEntries(_downloadContext->getFileEntries());
 }
 
+bool UnknownLengthPieceStorage::hasMissingPiece(const SharedHandle<Peer>& peer)
+{
+  abort();
+}
+
+SharedHandle<Piece> UnknownLengthPieceStorage::getMissingPiece(const SharedHandle<Peer>& peer)
+{
+  abort();
+}
+
+SharedHandle<Piece> UnknownLengthPieceStorage::getMissingFastPiece(const SharedHandle<Peer>& 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();

+ 7 - 22
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>& peer)
-  {
-    abort();
-  }
+  virtual bool hasMissingPiece(const SharedHandle<Peer>& 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<Piece> getMissingPiece(const SharedHandle<Peer>& peer)
-  {
-    abort();
-  }
+  virtual SharedHandle<Piece> getMissingPiece(const SharedHandle<Peer>& 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<Piece> getMissingFastPiece(const SharedHandle<Peer>& peer)
-  {
-    abort();
-  }
+  virtual SharedHandle<Piece> getMissingFastPiece(const SharedHandle<Peer>& 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

+ 38 - 10
src/Util.cc

@@ -100,7 +100,8 @@ std::pair<std::string, std::string> 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");
   }

+ 3 - 1
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

+ 9 - 10
src/array_fun.h

@@ -35,6 +35,7 @@
 #ifndef _D_ARRAY_FUN_H_
 #define _D_ARRAY_FUN_H_
 
+#include <cstdlib>
 #include <functional>
 
 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<typename T, std::size_t N>
+template<typename T, size_t N>
 char (&char_array_ref(T (&)[N]))[N];
 
-template<typename T, std::size_t N>
-std::size_t
-arrayLength(T (&a)[N])
+template<typename T, size_t N>
+size_t arrayLength(T (&a)[N])
 {
   return sizeof(char_array_ref(a));
 }
 
 template<typename T>
-std::size_t
-arrayLength(T (&a)[0u])
+size_t arrayLength(T (&a)[0u])
 {
   return 0;
 }

+ 1 - 0
src/option_processing.cc

@@ -44,6 +44,7 @@
 #include "a2io.h"
 #include "help_tags.h"
 #include "File.h"
+#include <cstdlib>
 #include <fstream>
 #include <sstream>
 #include <iostream>

+ 1 - 0
test/BNodeTest.cc

@@ -4,6 +4,7 @@
 #include "DHTUtil.h"
 #include "Exception.h"
 #include "Util.h"
+#include <cstring>
 #include <cppunit/extensions/HelperMacros.h>
 
 namespace aria2 {

+ 1 - 0
test/BitfieldManTest.cc

@@ -1,5 +1,6 @@
 #include "BitfieldMan.h"
 #include "FixedNumberRandomizer.h"
+#include <cstring>
 #include <cppunit/extensions/HelperMacros.h>
 
 namespace aria2 {

+ 2 - 0
test/DHTBucketTest.cc

@@ -2,6 +2,8 @@
 #include "DHTNode.h"
 #include "Exception.h"
 #include "Util.h"
+#include <cstring>
+#include <algorithm>
 #include <cppunit/extensions/HelperMacros.h>
 
 namespace aria2 {

+ 1 - 0
test/DHTIDCloserTest.cc

@@ -3,6 +3,7 @@
 #include "DHTIDCloser.h"
 #include "Exception.h"
 #include "Util.h"
+#include <cstring>
 #include <algorithm>
 #include <cppunit/extensions/HelperMacros.h>
 

+ 1 - 0
test/DHTMessageFactoryImplTest.cc

@@ -17,6 +17,7 @@
 #include "DHTGetPeersReplyMessage.h"
 #include "DHTAnnouncePeerMessage.h"
 #include "DHTAnnouncePeerReplyMessage.h"
+#include <cstring>
 #include <iostream>
 #include <cppunit/extensions/HelperMacros.h>
 

+ 1 - 0
test/DHTUtilTest.cc

@@ -1,6 +1,7 @@
 #include "DHTUtil.h"
 #include "Exception.h"
 #include "Util.h"
+#include <cstring>
 #include <cppunit/extensions/HelperMacros.h>
 
 namespace aria2 {

+ 1 - 0
test/DefaultBtContextTest.cc

@@ -4,6 +4,7 @@
 #include "AnnounceTier.h"
 #include "FixedNumberRandomizer.h"
 #include "FileEntry.h"
+#include <cstring>
 #include <iostream>
 #include <cppunit/extensions/HelperMacros.h>
 

+ 1 - 0
test/FixedNumberRandomizer.h

@@ -2,6 +2,7 @@
 #define _D_FIXED_NUMBER_RANDOMIZER_H_
 
 #include "Randomizer.h"
+#include <cstdlib>
 
 namespace aria2 {
 

+ 1 - 0
test/MockBtContext.h

@@ -4,6 +4,7 @@
 #include "BtContext.h"
 #include "Util.h"
 #include "AnnounceTier.h"
+#include <cstring>
 
 namespace aria2 {
 

+ 4 - 2
test/MultiDiskAdaptorTest.cc

@@ -2,6 +2,8 @@
 #include "FileEntry.h"
 #include "Exception.h"
 #include <string>
+#include <cerrno>
+#include <cstring>
 #include <cppunit/extensions/HelperMacros.h>
 
 namespace aria2 {
@@ -48,12 +50,12 @@ std::deque<SharedHandle<FileEntry> > 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");
   }
 }
 

+ 22 - 0
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<DiskWriter> dw = new ByteArrayDiskWriter();