浏览代码

2010-10-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Fixed compiler warning about printf format.
	* src/AdaptiveURISelector.cc
	* src/BtPieceMessage.cc
	* src/DHTAbstractNodeLookupTask.h
	* src/DHTMessageFactoryImpl.cc
	* src/DHTPeerLookupTask.cc
	* src/DHTReplaceNodeTask.cc
	* src/DefaultBtAnnounce.cc
	* src/DefaultBtInteractive.cc
	* src/DefaultBtMessageDispatcher.cc
	* src/DefaultBtProgressInfoFile.cc
	* src/DefaultBtRequestFactory.cc
	* src/DefaultExtensionMessageFactory.cc
	* src/DefaultPieceStorage.cc
	* src/DownloadCommand.cc
	* src/FileAllocationCommand.cc
	* src/FileEntry.cc
	* src/HandshakeExtensionMessage.cc
	* src/IteratableChunkChecksumValidator.cc
	* src/LibgcryptDHKeyExchange.h
	* src/LibsslDHKeyExchange.h
	* src/LpdDispatchMessageCommand.cc
	* src/MSEHandshake.cc
	* src/MessageDigestHelper.cc
	* src/MultiDiskAdaptor.cc
	* src/PeerConnection.cc
	* src/SegmentMan.cc
	* src/TimedHaltCommand.cc
	* src/UTMetadataRequestExtensionMessage.cc
	* src/UTPexExtensionMessage.cc
	* src/bencode2.cc
	* src/bittorrent_helper.cc
	* src/message.h
Tatsuhiro Tsujikawa 15 年之前
父节点
当前提交
b7df39b7ae

+ 36 - 0
ChangeLog

@@ -1,3 +1,39 @@
+2010-10-28  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Fixed compiler warning about printf format.
+	* src/AdaptiveURISelector.cc
+	* src/BtPieceMessage.cc
+	* src/DHTAbstractNodeLookupTask.h
+	* src/DHTMessageFactoryImpl.cc
+	* src/DHTPeerLookupTask.cc
+	* src/DHTReplaceNodeTask.cc
+	* src/DefaultBtAnnounce.cc
+	* src/DefaultBtInteractive.cc
+	* src/DefaultBtMessageDispatcher.cc
+	* src/DefaultBtProgressInfoFile.cc
+	* src/DefaultBtRequestFactory.cc
+	* src/DefaultExtensionMessageFactory.cc
+	* src/DefaultPieceStorage.cc
+	* src/DownloadCommand.cc
+	* src/FileAllocationCommand.cc
+	* src/FileEntry.cc
+	* src/HandshakeExtensionMessage.cc
+	* src/IteratableChunkChecksumValidator.cc
+	* src/LibgcryptDHKeyExchange.h
+	* src/LibsslDHKeyExchange.h
+	* src/LpdDispatchMessageCommand.cc
+	* src/MSEHandshake.cc
+	* src/MessageDigestHelper.cc
+	* src/MultiDiskAdaptor.cc
+	* src/PeerConnection.cc
+	* src/SegmentMan.cc
+	* src/TimedHaltCommand.cc
+	* src/UTMetadataRequestExtensionMessage.cc
+	* src/UTPexExtensionMessage.cc
+	* src/bencode2.cc
+	* src/bittorrent_helper.cc
+	* src/message.h
+
 2010-10-28  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Fixed compiler warning when checking c-ares version.

+ 3 - 2
src/AdaptiveURISelector.cc

@@ -112,8 +112,9 @@ void AdaptiveURISelector::mayRetryWithIncreasedTimeout(FileEntry* fileEntry)
     for(std::deque<std::string>::const_iterator i = uris.begin(),
           eoi = uris.end(); i != eoi; ++i) {
       logger_->debug("AdaptiveURISelector: will retry server with increased"
-                     " timeout (%d s): %s",
-                     requestGroup_->getTimeout(), (*i).c_str());
+                     " timeout (%ld s): %s",
+                     static_cast<long int>(requestGroup_->getTimeout()),
+                     (*i).c_str());
     }
   }
 }

+ 15 - 8
src/BtPieceMessage.cc

@@ -110,8 +110,10 @@ void BtPieceMessage::doReceivedAction()
     if(getLogger()->debug()) {
       getLogger()->debug(MSG_PIECE_RECEIVED,
                          util::itos(getCuid()).c_str(),
-                         index_, begin_, blockLength_, offset,
-                         slot.getBlockIndex());
+                         static_cast<unsigned long>(index_),
+                         begin_, blockLength_,
+                         static_cast<long long int>(offset),
+                         static_cast<unsigned long>(slot.getBlockIndex()));
     }
     getPieceStorage()->getDiskAdaptor()->writeData
       (block_, blockLength_, offset);
@@ -133,8 +135,9 @@ void BtPieceMessage::doReceivedAction()
     }
   } else {
     if(getLogger()->debug()) {
-      getLogger()->debug("CUID#%s - RequestSlot not found, index=%d, begin=%d",
-                         util::itos(getCuid()).c_str(), index_, begin_);
+      getLogger()->debug("CUID#%s - RequestSlot not found, index=%lu, begin=%u",
+                         util::itos(getCuid()).c_str(),
+                         static_cast<unsigned long>(index_), begin_);
     }
   }
 }
@@ -242,7 +245,8 @@ void BtPieceMessage::onNewPiece(const SharedHandle<Piece>& piece)
 {
   if(getLogger()->info()) {
     getLogger()->info(MSG_GOT_NEW_PIECE,
-                      util::itos(getCuid()).c_str(), piece->getIndex());
+                      util::itos(getCuid()).c_str(),
+                      static_cast<unsigned long>(piece->getIndex()));
   }
   getPieceStorage()->completePiece(piece);
   getPieceStorage()->advertisePiece(getCuid(), piece->getIndex());
@@ -252,7 +256,8 @@ void BtPieceMessage::onWrongPiece(const SharedHandle<Piece>& piece)
 {
   if(getLogger()->info()) {
     getLogger()->info(MSG_GOT_WRONG_PIECE,
-                      util::itos(getCuid()).c_str(), piece->getIndex());
+                      util::itos(getCuid()).c_str(),
+                      static_cast<unsigned long>(piece->getIndex()));
   }
   erasePieceOnDisk(piece);
   piece->clearAllBlock();
@@ -284,7 +289,8 @@ void BtPieceMessage::onChokingEvent(const BtChokingEvent& event)
     if(getLogger()->debug()) {
       getLogger()->debug(MSG_REJECT_PIECE_CHOKED,
                          util::itos(getCuid()).c_str(),
-                         index_, begin_, blockLength_);
+                         static_cast<unsigned long>(index_),
+                         begin_, blockLength_);
     }
     if(getPeer()->isFastExtensionEnabled()) {
       BtMessageHandle rej =
@@ -307,7 +313,8 @@ void BtPieceMessage::onCancelSendingPieceEvent
     if(getLogger()->debug()) {
       getLogger()->debug(MSG_REJECT_PIECE_CANCEL,
                          util::itos(getCuid()).c_str(),
-                         index_, begin_, blockLength_);
+                         static_cast<unsigned long>(index_),
+                         begin_, blockLength_);
     }
     if(getPeer()->isFastExtensionEnabled()) {
       BtMessageHandle rej =

+ 6 - 4
src/DHTAbstractNodeLookupTask.h

@@ -110,8 +110,8 @@ private:
       setFinished(true);
     } else {
       if(getLogger()->debug()) {
-        getLogger()->debug("%d in flight message for node ID %s",
-                           inFlightMessage_,
+        getLogger()->debug("%lu in flight message for node ID %s",
+                           static_cast<unsigned long>(inFlightMessage_),
                            util::toHex(targetID_, DHT_ID_LENGTH).c_str());
       }
     }
@@ -199,12 +199,14 @@ public:
       }
     }
     if(getLogger()->debug()) {
-      getLogger()->debug("%u node lookup entries added.", count);
+      getLogger()->debug("%lu node lookup entries added.",
+                         static_cast<unsigned long>(count));
     }
     std::stable_sort(entries_.begin(), entries_.end(), DHTIDCloser(targetID_));
     entries_.erase(std::unique(entries_.begin(), entries_.end()), entries_.end());
     if(getLogger()->debug()) {
-      getLogger()->debug("%u node lookup entries are unique.", entries_.size());
+      getLogger()->debug("%lu node lookup entries are unique.",
+                         static_cast<unsigned long>(entries_.size()));
     }
     if(entries_.size() > DHTBucket::K) {
       entries_.erase(entries_.begin()+DHTBucket::K, entries_.end());

+ 7 - 6
src/DHTMessageFactoryImpl.cc

@@ -123,8 +123,8 @@ static const String* getString(const List* list, size_t index)
     return c;
   } else {
     throw DL_ABORT_EX
-      (StringFormat("Malformed DHT message. element[%u] is not String.",
-                    index).str());
+      (StringFormat("Malformed DHT message. element[%lu] is not String.",
+                    static_cast<unsigned long>(index)).str());
   }
 }
 
@@ -135,8 +135,8 @@ static const Integer* getInteger(const List* list, size_t index)
     return c;
   } else {
     throw DL_ABORT_EX
-      (StringFormat("Malformed DHT message. element[%u] is not Integer.",
-                    index).str());
+      (StringFormat("Malformed DHT message. element[%lu] is not Integer.",
+                    static_cast<unsigned long>(index)).str());
   }
 }
 
@@ -156,8 +156,9 @@ void DHTMessageFactoryImpl::validateID(const String* id) const
   if(id->s().size() != DHT_ID_LENGTH) {
     throw DL_ABORT_EX
       (StringFormat("Malformed DHT message. Invalid ID length."
-                    " Expected:%d, Actual:%d",
-                    DHT_ID_LENGTH, id->s().size()).str());
+                    " Expected:%lu, Actual:%lu",
+                    static_cast<unsigned long>(DHT_ID_LENGTH),
+                    static_cast<unsigned long>(id->s().size())).str());
   }
 }
 

+ 2 - 1
src/DHTPeerLookupTask.cc

@@ -75,7 +75,8 @@ void DHTPeerLookupTask::onReceivedInternal
   peerStorage_->addPeer(message->getValues());
   peers_.insert(peers_.end(),
                 message->getValues().begin(), message->getValues().end());
-  getLogger()->info("Received %u peers.", message->getValues().size());
+  getLogger()->info("Received %lu peers.",
+                    static_cast<unsigned long>(message->getValues().size()));
 }
   
 SharedHandle<DHTMessage> DHTPeerLookupTask::createMessage

+ 3 - 2
src/DHTReplaceNodeTask.cc

@@ -84,8 +84,9 @@ void DHTReplaceNodeTask::onTimeout(const SharedHandle<DHTNode>& node)
 {
   ++numRetry_;
   if(numRetry_ >= MAX_RETRY) {
-    getLogger()->info("ReplaceNode: Ping failed %u times. Replace %s with %s.",
-                      numRetry_, node->toString().c_str(),
+    getLogger()->info("ReplaceNode: Ping failed %lu times. Replace %s with %s.",
+                      static_cast<unsigned long>(numRetry_),
+                      node->toString().c_str(),
                       newNode_->toString().c_str());
     node->markBad();
     bucket_->addNode(newNode_);

+ 2 - 2
src/DefaultBtAnnounce.cc

@@ -245,14 +245,14 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
   if(ival && ival->i() > 0) {
     interval_ = ival->i();
     if(logger_->debug()) {
-      logger_->debug("Interval:%d", interval_);
+      logger_->debug("Interval:%ld", static_cast<long int>(interval_));
     }
   }
   const Integer* mival = asInteger(dict->get(BtAnnounce::MIN_INTERVAL));
   if(mival && mival->i() > 0) {
     minInterval_ = mival->i();
     if(logger_->debug()) {
-      logger_->debug("Min interval:%d", minInterval_);
+      logger_->debug("Min interval:%ld", static_cast<long int>(minInterval_));
     }
     minInterval_ = std::min(minInterval_, interval_);
   } else {

+ 4 - 2
src/DefaultBtInteractive.cc

@@ -462,7 +462,8 @@ void DefaultBtInteractive::checkActiveInteraction()
       // TODO change the message
       throw DL_ABORT_EX
         (StringFormat("Disconnect peer because we are not interested each other"
-                      " after %u second(s).", interval).str());
+                      " after %ld second(s).",
+                      static_cast<long int>(interval)).str());
     }
   }
   // Since the peers which are *just* connected and do nothing to improve
@@ -473,7 +474,8 @@ void DefaultBtInteractive::checkActiveInteraction()
     if(inactiveTime >= interval) {
       peer_->setDisconnectedGracefully(true);
       throw DL_ABORT_EX
-        (StringFormat(EX_DROP_INACTIVE_CONNECTION, interval).str());
+        (StringFormat(EX_DROP_INACTIVE_CONNECTION,
+                      static_cast<long int>(interval)).str());
     }
   }
 }

+ 12 - 10
src/DefaultBtMessageDispatcher.cc

@@ -157,9 +157,9 @@ public:
     if(logger_->debug()) {
       logger_->debug(MSG_DELETING_REQUEST_SLOT,
                      util::itos(cuid_).c_str(),
-                     slot.getIndex(),
-                     slot.getBlockIndex());
-      logger_->debug("index=%d, begin=%d", slot.getIndex(), slot.getBegin());
+                     static_cast<unsigned long>(slot.getIndex()),
+                     slot.getBegin(),
+                     static_cast<unsigned long>(slot.getBlockIndex()));
     }
     piece_->cancelBlock(slot.getBlockIndex());
   }
@@ -210,9 +210,9 @@ public:
       if(logger_->debug()) {
         logger_->debug(MSG_DELETING_REQUEST_SLOT_CHOKED,
                        util::itos(cuid_).c_str(),
-                       slot.getIndex(),
-                       slot.getBlockIndex());
-        logger_->debug("index=%d, begin=%d", slot.getIndex(), slot.getBegin());
+                       static_cast<unsigned long>(slot.getIndex()),
+                       slot.getBegin(),
+                       static_cast<unsigned long>(slot.getBlockIndex()));
       }
       SharedHandle<Piece> piece = pieceStorage_->getPiece(slot.getIndex());
       piece->cancelBlock(slot.getBlockIndex());
@@ -289,8 +289,9 @@ public:
       if(logger_->debug()) {
         logger_->debug(MSG_DELETING_REQUEST_SLOT_TIMEOUT,
                        util::itos(cuid_).c_str(),
-                       slot.getBlockIndex());
-        logger_->debug("index=%d, begin=%d", slot.getIndex(), slot.getBegin());
+                       static_cast<unsigned long>(slot.getIndex()),
+                       slot.getBegin(),
+                       static_cast<unsigned long>(slot.getBlockIndex()));
       }
       slot.getPiece()->cancelBlock(slot.getBlockIndex());
       peer_->snubbing(true);
@@ -298,8 +299,9 @@ public:
       if(logger_->debug()) {
         logger_->debug(MSG_DELETING_REQUEST_SLOT_ACQUIRED,
                        util::itos(cuid_).c_str(),
-                       slot.getBlockIndex());
-        logger_->debug("index=%d, begin=%d", slot.getIndex(), slot.getBegin());
+                       static_cast<unsigned long>(slot.getIndex()),
+                       slot.getBegin(),
+                       static_cast<unsigned long>(slot.getBlockIndex()));
       }
       messageDispatcher_->addMessageToQueue
         (messageFactory_->createCancelMessage(slot.getIndex(),

+ 3 - 2
src/DefaultBtProgressInfoFile.cc

@@ -379,8 +379,9 @@ void DefaultBtProgressInfoFile::load()
       if(piece->getBitfieldLength() != bitfieldLength) {
         throw DL_ABORT_EX
           (StringFormat("piece bitfield length mismatch."
-                        " expected: %u actual: %u",
-                        piece->getBitfieldLength(), bitfieldLength).str());
+                        " expected: %lu actual: %u",
+                        static_cast<unsigned long>(piece->getBitfieldLength()),
+                        bitfieldLength).str());
       }
       array_ptr<unsigned char> pieceBitfield
         (new unsigned char[bitfieldLength]);

+ 12 - 10
src/DefaultBtRequestFactory.cc

@@ -174,11 +174,12 @@ void DefaultBtRequestFactory::createRequestMessages
       for(std::vector<size_t>::const_iterator i = blockIndexes.begin(),
             eoi2 = blockIndexes.end(); i != eoi2; ++i) {
         if(logger_->debug()) {
-          logger_->debug("Creating RequestMessage index=%u, begin=%u,"
-                         " blockIndex=%u",
-                         piece->getIndex(),
-                         (*i)*piece->getBlockLength(),
-                         (*i));
+          logger_->debug
+            ("Creating RequestMessage index=%lu, begin=%u,"
+             " blockIndex=%lu",
+             static_cast<unsigned long>(piece->getIndex()),
+             static_cast<unsigned int>((*i)*piece->getBlockLength()),
+             static_cast<unsigned long>(*i));
         }
         requests.push_back
           (messageFactory_->createRequestMessage(piece, *i));
@@ -219,11 +220,12 @@ void DefaultBtRequestFactory::createRequestMessagesOnEndGame
       if(!dispatcher_->isOutstandingRequest(piece->getIndex(),
                                            blockIndex)) {
         if(logger_->debug()) {
-          logger_->debug("Creating RequestMessage index=%u, begin=%u,"
-                         " blockIndex=%u",
-                         piece->getIndex(),
-                         blockIndex*piece->getBlockLength(),
-                         blockIndex);
+          logger_->debug
+            ("Creating RequestMessage index=%lu, begin=%u,"
+             " blockIndex=%lu",
+             static_cast<unsigned long>(piece->getIndex()),
+             static_cast<unsigned int>(blockIndex*piece->getBlockLength()),
+             static_cast<unsigned long>(blockIndex));
         }
         requests.push_back(messageFactory_->createRequestMessage
                            (piece, blockIndex));

+ 7 - 4
src/DefaultExtensionMessageFactory.cc

@@ -94,8 +94,10 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
       return m;
     } else if(extensionName == "ut_metadata") {
       if(length == 0) {
-        throw DL_ABORT_EX(StringFormat(MSG_TOO_SMALL_PAYLOAD_SIZE,
-                                       "ut_metadata", length).str());
+        throw DL_ABORT_EX
+          (StringFormat(MSG_TOO_SMALL_PAYLOAD_SIZE,
+                        "ut_metadata",
+                        static_cast<unsigned long>(length)).str());
       }
       size_t end;
       SharedHandle<ValueBase> decoded = bencode2::decode(data+1, length-1, end);
@@ -148,8 +150,9 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
         return m;
       }
       default:
-        throw DL_ABORT_EX(StringFormat("Bad ut_metadata: unknown msg_type=%u",
-                                       msgType->i()).str());
+        throw DL_ABORT_EX
+          (StringFormat("Bad ut_metadata: unknown msg_type=%u",
+                        static_cast<unsigned int>(msgType->i())).str());
       }
     } else {
       throw DL_ABORT_EX

+ 2 - 1
src/DefaultPieceStorage.cc

@@ -667,7 +667,8 @@ void DefaultPieceStorage::removeAdvertisedPiece(time_t elapsed)
     std::find_if(haves_.begin(), haves_.end(), FindElapsedHave(elapsed));
   if(itr != haves_.end()) {
     if(logger_->debug()) {
-      logger_->debug(MSG_REMOVED_HAVE_ENTRY, haves_.end()-itr);
+      logger_->debug(MSG_REMOVED_HAVE_ENTRY,
+                     static_cast<unsigned long>(haves_.end()-itr));
     }
     haves_.erase(itr, haves_.end());
   }

+ 3 - 2
src/DownloadCommand.cc

@@ -345,14 +345,15 @@ void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
     getSegmentMan()->completeSegment(getCuid(), segment);
   } else {
     getLogger()->info(EX_INVALID_CHUNK_CHECKSUM,
-                      segment->getIndex(),
+                      static_cast<unsigned long>(segment->getIndex()),
                       util::itos(segment->getPosition(), true).c_str(),
                       expectedPieceHash.c_str(),
                       actualPieceHash.c_str());
     segment->clear();
     getSegmentMan()->cancelSegment(getCuid());
     throw DL_RETRY_EX
-      (StringFormat("Invalid checksum index=%d", segment->getIndex()).str());
+      (StringFormat("Invalid checksum index=%lu",
+                    static_cast<unsigned long>(segment->getIndex())).str());
   }
 }
 

+ 1 - 1
src/FileAllocationCommand.cc

@@ -71,7 +71,7 @@ bool FileAllocationCommand::executeInternal()
     if(getLogger()->debug()) {
       getLogger()->debug
         (MSG_ALLOCATION_COMPLETED,
-         timer_.difference(global::wallclock),
+         static_cast<long int>(timer_.difference(global::wallclock)),
          util::itos(getRequestGroup()->getTotalLength(), true).c_str());
     }
     getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();

+ 3 - 2
src/FileEntry.cc

@@ -272,8 +272,9 @@ void FileEntry::removeURIWhoseHostnameIs(const std::string& hostname)
     }
   }
   if(logger_->debug()) {
-    logger_->debug("Removed %d duplicate hostname URIs for path=%s",
-                   uris_.size()-newURIs.size(), getPath().c_str());
+    logger_->debug("Removed %lu duplicate hostname URIs for path=%s",
+                   static_cast<unsigned long>(uris_.size()-newURIs.size()),
+                   getPath().c_str());
   }
   uris_.swap(newURIs);
 }

+ 2 - 1
src/HandshakeExtensionMessage.cc

@@ -167,7 +167,8 @@ HandshakeExtensionMessage::create(const unsigned char* data, size_t length)
   if(length < 1) {
     throw DL_ABORT_EX
       (StringFormat(MSG_TOO_SMALL_PAYLOAD_SIZE,
-                    EXTENSION_NAME.c_str(), length).str());
+                    EXTENSION_NAME.c_str(),
+                    static_cast<unsigned long>(length)).str());
   }
   HandshakeExtensionMessageHandle msg(new HandshakeExtensionMessage());
   if(LogFactory::getInstance()->debug()) {

+ 3 - 3
src/IteratableChunkChecksumValidator.cc

@@ -88,7 +88,7 @@ void IteratableChunkChecksumValidator::validateChunk()
       } else {
         if(logger_->info()) {
           logger_->info(EX_INVALID_CHUNK_CHECKSUM,
-                        currentIndex_,
+                        static_cast<unsigned long>(currentIndex_),
                         util::itos(getCurrentOffset(), true).c_str(),
                         dctx_->getPieceHashes()[currentIndex_].c_str(),
                         actualChecksum.c_str());
@@ -97,9 +97,9 @@ void IteratableChunkChecksumValidator::validateChunk()
       }
     } catch(RecoverableException& ex) {
       if(logger_->debug()) {
-        logger_->debug("Caught exception while validating piece index=%d."
+        logger_->debug("Caught exception while validating piece index=%lu."
                        " Some part of file may be missing. Continue operation.",
-                       ex, currentIndex_);
+                       ex, static_cast<unsigned long>(currentIndex_));
       }
       bitfield_->unsetBit(currentIndex_);
     }

+ 7 - 4
src/LibgcryptDHKeyExchange.h

@@ -113,8 +113,10 @@ public:
   {
     if(outLength < keyLength_) {
       throw DL_ABORT_EX
-        (StringFormat("Insufficient buffer for public key. expect:%u, actual:%u",
-                      keyLength_, outLength).str());
+        (StringFormat
+         ("Insufficient buffer for public key. expect:%lu, actual:%lu",
+          static_cast<unsigned long>(keyLength_),
+          static_cast<unsigned long>(outLength)).str());
     }
     memset(out, 0, outLength);
     size_t publicKeyBytes = (gcry_mpi_get_nbits(publicKey_)+7)/8;
@@ -139,8 +141,9 @@ public:
   {
     if(outLength < keyLength_) {
       throw DL_ABORT_EX
-        (StringFormat("Insufficient buffer for secret. expect:%u, actual:%u",
-                      keyLength_, outLength).str());
+        (StringFormat("Insufficient buffer for secret. expect:%lu, actual:%lu",
+                      static_cast<unsigned long>(keyLength_),
+                      static_cast<unsigned long>(outLength)).str());
     }
     gcry_mpi_t peerPublicKey;
     {

+ 17 - 6
src/LibsslDHKeyExchange.h

@@ -124,8 +124,10 @@ public:
   {
     if(outLength < keyLength_) {
       throw DL_ABORT_EX
-        (StringFormat("Insufficient buffer for public key. expect:%u, actual:%u",
-                      keyLength_, outLength).str());
+        (StringFormat
+         ("Insufficient buffer for public key. expect:%lu, actual:%lu",
+          static_cast<unsigned long>(keyLength_),
+          static_cast<unsigned long>(outLength)).str());
     }
     memset(out, 0, outLength);
     size_t publicKeyBytes = BN_num_bytes(publicKey_);
@@ -133,7 +135,11 @@ public:
     size_t nwritten = BN_bn2bin(publicKey_, out+offset);
     if(nwritten != publicKeyBytes) {
       throw DL_ABORT_EX
-        (StringFormat("BN_bn2bin in DHKeyExchange::getPublicKey, %u bytes written, but %u bytes expected.", nwritten, publicKeyBytes).str());
+        (StringFormat
+         ("BN_bn2bin in DHKeyExchange::getPublicKey, %lu bytes written,"
+          " but %lu bytes expected.",
+          static_cast<unsigned long>(nwritten),
+          static_cast<unsigned long>(publicKeyBytes)).str());
     }
     return nwritten;
   }
@@ -151,8 +157,9 @@ public:
   {
     if(outLength < keyLength_) {
       throw DL_ABORT_EX
-        (StringFormat("Insufficient buffer for secret. expect:%u, actual:%u",
-                      keyLength_, outLength).str());
+        (StringFormat("Insufficient buffer for secret. expect:%lu, actual:%lu",
+                      static_cast<unsigned long>(keyLength_),
+                      static_cast<unsigned long>(outLength)).str());
     }
 
 
@@ -172,7 +179,11 @@ public:
     BN_free(secret);
     if(nwritten != secretBytes) {
       throw DL_ABORT_EX
-        (StringFormat("BN_bn2bin in DHKeyExchange::getPublicKey, %u bytes written, but %u bytes expected.", nwritten, secretBytes).str());
+        (StringFormat
+         ("BN_bn2bin in DHKeyExchange::getPublicKey, %lu bytes written,"
+          " but %lu bytes expected.",
+          static_cast<unsigned long>(nwritten),
+          static_cast<unsigned long>(secretBytes)).str());
     }
     return nwritten;
   }

+ 2 - 1
src/LpdDispatchMessageCommand.cc

@@ -73,7 +73,8 @@ bool LpdDispatchMessageCommand::execute()
       } else {
         ++tryCount_;
         if(tryCount_ >= 5) {
-          getLogger()->info("Sending LPD message %u times but all failed.");
+          getLogger()->info("Sending LPD message %u times but all failed.",
+                            tryCount_);
           dispatcher_->resetAnnounceTimer();
           tryCount_ = 0;
         } else {

+ 6 - 4
src/MSEHandshake.cc

@@ -351,8 +351,9 @@ bool MSEHandshake::findInitiatorVCMarker()
   socket_->readData(rbuf_+rbufLength_, toRead);
   rbufLength_ += toRead;
   if(logger_->debug()) {
-    logger_->debug("CUID#%s - VC marker found at %u",
-                   util::itos(cuid_).c_str(), markerIndex_);
+    logger_->debug("CUID#%s - VC marker found at %lu",
+                   util::itos(cuid_).c_str(),
+                   static_cast<unsigned long>(markerIndex_));
   }
   verifyVC(rbuf_+markerIndex_);
   // reset rbufLength_
@@ -452,8 +453,9 @@ bool MSEHandshake::findReceiverHashMarker()
   socket_->readData(rbuf_+rbufLength_, toRead);
   rbufLength_ += toRead;
   if(logger_->debug()) {
-    logger_->debug("CUID#%s - Hash marker found at %u.",
-                   util::itos(cuid_).c_str(), markerIndex_);
+    logger_->debug("CUID#%s - Hash marker found at %lu.",
+                   util::itos(cuid_).c_str(),
+                   static_cast<unsigned long>(markerIndex_));
   }
   verifyReq1Hash(rbuf_+markerIndex_);
   // reset rbufLength_

+ 5 - 2
src/MessageDigestHelper.cc

@@ -131,8 +131,11 @@ void MessageDigestHelper::digest(unsigned char* md, size_t mdLength,
 {
   if(mdLength < MessageDigestContext::digestLength(algo)) {
     throw DL_ABORT_EX
-      (StringFormat("Insufficient space for storing message digest: %d required, but only %d is allocated",
-                    MessageDigestContext::digestLength(algo), mdLength).str());
+      (StringFormat
+       ("Insufficient space for storing message digest:"
+        " %lu required, but only %lu is allocated",
+        static_cast<unsigned long>(MessageDigestContext::digestLength(algo)),
+        static_cast<unsigned long>(mdLength)).str());
   }
   MessageDigestContext ctx;
   ctx.trySetAlgo(algo);

+ 4 - 2
src/MultiDiskAdaptor.cc

@@ -207,7 +207,8 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
           getLogger()->debug("Checking adjacent backward file to %s"
                              " whose lastPieceStartOffset+pieceLength_=%lld",
                              fileEntry->getPath().c_str(),
-                             lastPieceStartOffset+pieceLength_);
+                             static_cast<long long int>
+                             (lastPieceStartOffset+pieceLength_));
         }
         ++itr;
         // adjacent backward files are not needed to be allocated. They
@@ -218,7 +219,8 @@ void MultiDiskAdaptor::resetDiskWriterEntries()
           if(getLogger()->debug()) {
             getLogger()->debug("file=%s, offset=%lld",
                                (*itr)->getFileEntry()->getPath().c_str(),
-                               (*itr)->getFileEntry()->getOffset());
+                               static_cast<long long int>
+                               ((*itr)->getFileEntry()->getOffset()));
           }
           if((*itr)->getFileEntry()->getOffset() <
              static_cast<off_t>(lastPieceStartOffset+pieceLength_)) {

+ 1 - 1
src/PeerConnection.cc

@@ -274,7 +274,7 @@ ssize_t PeerConnection::sendPendingData()
 {
   ssize_t writtenLength = socketBuffer_.send();
   if(logger_->debug()) {
-    logger_->debug("sent %d byte(s).", writtenLength);
+    logger_->debug("sent %ld byte(s).", static_cast<long int>(writtenLength));
   }
   return writtenLength;
 }

+ 17 - 12
src/SegmentMan.cc

@@ -114,8 +114,9 @@ SharedHandle<Segment> SegmentMan::checkoutSegment
     return SharedHandle<Segment>();
   }
   if(logger_->debug()) {
-    logger_->debug("Attach segment#%d to CUID#%s.",
-                   piece->getIndex(), util::itos(cuid).c_str());
+    logger_->debug("Attach segment#%lu to CUID#%s.",
+                   static_cast<unsigned long>(piece->getIndex()),
+                   util::itos(cuid).c_str());
   }
   SharedHandle<Segment> segment;
   if(piece->getLength() == 0) {
@@ -126,11 +127,12 @@ SharedHandle<Segment> SegmentMan::checkoutSegment
   SegmentEntryHandle entry(new SegmentEntry(cuid, segment));
   usedSegmentEntries_.push_back(entry);
   if(logger_->debug()) {
-    logger_->debug("index=%d, length=%d, segmentLength=%d, writtenLength=%d",
-                   segment->getIndex(),
-                   segment->getLength(),
-                   segment->getSegmentLength(),
-                   segment->getWrittenLength());
+    logger_->debug("index=%lu, length=%lu, segmentLength=%lu,"
+                   " writtenLength=%lu",
+                   static_cast<unsigned long>(segment->getIndex()),
+                   static_cast<unsigned long>(segment->getLength()),
+                   static_cast<unsigned long>(segment->getSegmentLength()),
+                   static_cast<unsigned long>(segment->getWrittenLength()));
   }
   if(piece->getLength() > 0) {
     std::map<size_t, size_t>::iterator positr =
@@ -138,8 +140,9 @@ SharedHandle<Segment> SegmentMan::checkoutSegment
     if(positr != segmentWrittenLengthMemo_.end()) {
       const size_t writtenLength = (*positr).second;
       if(logger_->debug()) {
-        logger_->debug("writtenLength(in memo)=%d, writtenLength=%d",
-                       writtenLength, segment->getWrittenLength());
+        logger_->debug("writtenLength(in memo)=%lu, writtenLength=%lu",
+                       static_cast<unsigned long>(writtenLength),
+                       static_cast<unsigned long>(segment->getWrittenLength()));
       }
       //  If the difference between cached writtenLength and segment's
       //  writtenLength is less than one block, we assume that these
@@ -247,13 +250,15 @@ SharedHandle<Segment> SegmentMan::getCleanSegmentIfOwnerIsIdle
 void SegmentMan::cancelSegment(const SharedHandle<Segment>& segment)
 {
   if(logger_->debug()) {
-    logger_->debug("Canceling segment#%d", segment->getIndex());
+    logger_->debug("Canceling segment#%lu",
+                   static_cast<unsigned long>(segment->getIndex()));
   }
   pieceStorage_->cancelPiece(segment->getPiece());
   segmentWrittenLengthMemo_[segment->getIndex()] = segment->getWrittenLength();
   if(logger_->debug()) {
-    logger_->debug("Memorized segment index=%u, writtenLength=%u",
-                   segment->getIndex(), segment->getWrittenLength());
+    logger_->debug("Memorized segment index=%lu, writtenLength=%lu",
+                   static_cast<unsigned long>(segment->getIndex()),
+                   static_cast<unsigned long>(segment->getWrittenLength()));
   }
 }
 

+ 2 - 1
src/TimedHaltCommand.cc

@@ -63,7 +63,8 @@ void TimedHaltCommand::preProcess()
 void TimedHaltCommand::process()
 {
   if(!getDownloadEngine()->isHaltRequested()) {
-    getLogger()->notice(MSG_TIME_HAS_PASSED, getInterval());
+    getLogger()->notice(MSG_TIME_HAS_PASSED,
+                        static_cast<long int>(getInterval()));
     if(forceHalt_) {
       getLogger()->notice("This is emergency shutdown.");
       getDownloadEngine()->requestForceHalt();

+ 2 - 1
src/UTMetadataRequestExtensionMessage.cc

@@ -94,7 +94,8 @@ void UTMetadataRequestExtensionMessage::doReceivedAction()
   } else {
     throw DL_ABORT_EX
       (StringFormat
-       ("Metadata piece index is too big. piece=%d", getIndex()).str());
+       ("Metadata piece index is too big. piece=%lu",
+        static_cast<unsigned long>(getIndex())).str());
   }
 }
 

+ 2 - 1
src/UTPexExtensionMessage.cc

@@ -176,7 +176,8 @@ UTPexExtensionMessage::create(const unsigned char* data, size_t len)
 {
   if(len < 1) {
     throw DL_ABORT_EX(StringFormat(MSG_TOO_SMALL_PAYLOAD_SIZE,
-                                   EXTENSION_NAME.c_str(), len).str());
+                                   EXTENSION_NAME.c_str(),
+                                   static_cast<unsigned long>(len)).str());
   }
   UTPexExtensionMessageHandle msg(new UTPexExtensionMessage(*data));
 

+ 3 - 2
src/bencode2.cc

@@ -73,8 +73,9 @@ static std::string decoderawstring(std::istream& ss)
   if(ss.gcount() != static_cast<int>(length)) {
     throw DL_ABORT_EX
       (StringFormat("Bencode decoding failed:"
-                    " Expected %lu bytes of data, but only %d read.",
-                    static_cast<unsigned long>(length), ss.gcount()).str());
+                    " Expected %lu bytes of data, but only %ld read.",
+                    static_cast<unsigned long>(length),
+                    static_cast<long int>(ss.gcount())).str());
   }
   return str;
 }

+ 4 - 2
src/bittorrent_helper.cc

@@ -862,7 +862,8 @@ void assertPayloadLengthGreater
 {
   if(actual <= threshold) {
     throw DL_ABORT_EX
-      (StringFormat(MSG_TOO_SMALL_PAYLOAD_SIZE, msgName.c_str(), actual).str());
+      (StringFormat(MSG_TOO_SMALL_PAYLOAD_SIZE, msgName.c_str(),
+                    static_cast<unsigned long>(actual)).str());
   }
 }
 
@@ -872,7 +873,8 @@ void assertPayloadLengthEqual
   if(expected != actual) {
     throw DL_ABORT_EX
       (StringFormat(EX_INVALID_PAYLOAD_SIZE, msgName.c_str(),
-                    actual, expected).str());
+                    static_cast<unsigned long>(actual),
+                    static_cast<unsigned long>(expected)).str());
   }
 }
 

+ 24 - 17
src/message.h

@@ -51,8 +51,8 @@
   "CUID#%s - %d times attempted, but no success. Download aborted."
 #define MSG_SEND_PEER_MESSAGE "CUID#%s - To: %s:%d %s"
 #define MSG_RECEIVE_PEER_MESSAGE "CUID#%s - From: %s:%d %s"
-#define MSG_GOT_NEW_PIECE "CUID#%s - we got new piece. index=%d"
-#define MSG_GOT_WRONG_PIECE "CUID#%s - we got wrong piece. index=%d"
+#define MSG_GOT_NEW_PIECE "CUID#%s - we got new piece. index=%lu"
+#define MSG_GOT_WRONG_PIECE "CUID#%s - we got wrong piece. index=%lu"
 #define MSG_DOWNLOAD_NOT_COMPLETE "CUID#%s - Download not complete: %s"
 #define MSG_DOWNLOAD_ALREADY_COMPLETED _("GID#%s - Download has already completed: %s")
 #define MSG_RESOLVING_HOSTNAME "CUID#%s - Resolving hostname %s"
@@ -63,23 +63,27 @@
 #define MSG_DNS_CACHE_HIT "CUID#%s - DNS cache hit: %s -> %s"
 #define MSG_CONNECTING_TO_PEER "CUID#%s - Connecting to the peer %s"
 #define MSG_PIECE_RECEIVED                                              \
-  "CUID#%s - Piece received. index=%d, begin=%d, length=%d, offset=%llu," \
-  " blockIndex=%d"
+  "CUID#%s - Piece received. index=%lu, begin=%u, length=%u, offset=%lld," \
+  " blockIndex=%lu"
 #define MSG_PIECE_BITFIELD "CUID#%s - Piece bitfield %s"
 #define MSG_REJECT_PIECE_CHOKED                                         \
   "CUID#%s - Reject piece message in queue because the peer has been choked." \
-  " index=%d, begin=%d, length=%d"
+  " index=%lu, begin=%u, length=%u"
 #define MSG_REJECT_PIECE_CANCEL                                         \
   "CUID#%s - Reject piece message in queue because cancel message received." \
-  " index=%d, begin=%d, length=%d"
+  " index=%lu, begin=%u, length=%u"
 #define MSG_FILE_VALIDATION_FAILURE                             \
   "CUID#%s - Exception caught while validating file integrity."
 #define MSG_PEER_INTERESTED "CUID#%s - Interested in the peer"
 #define MSG_PEER_NOT_INTERESTED "CUID#%s - Not interested in the peer"
-#define MSG_DELETING_REQUEST_SLOT "CUID#%s - Deleting request slot index=%d, blockIndex=%d"
-#define MSG_DELETING_REQUEST_SLOT_CHOKED "CUID#%s - Deleting request slot index=%d, blockIndex=%d because localhost got choked."
-#define MSG_DELETING_REQUEST_SLOT_TIMEOUT "CUID#%s - Deleting request slot blockIndex=%d because of time out"
-#define MSG_DELETING_REQUEST_SLOT_ACQUIRED "CUID#%s - Deleting request slot blockIndex=%d because the block has been acquired."
+#define MSG_DELETING_REQUEST_SLOT "CUID#%s - Deleting request slot index=%lu," \
+  " begin=%u, blockIndex=%lu"
+#define MSG_DELETING_REQUEST_SLOT_CHOKED "CUID#%s - Deleting request slot" \
+  " index=%lu, begin=%u, blockIndex=%lu because localhost got choked."
+#define MSG_DELETING_REQUEST_SLOT_TIMEOUT "CUID#%s - Deleting request slot" \
+  " index=%lu, begin=%u, blockIndex=%lu because of time out"
+#define MSG_DELETING_REQUEST_SLOT_ACQUIRED "CUID#%s - Deleting request slot" \
+  " index=%lu, begin=%u, blockIndex=%lu because the block has been acquired."
 #define MSG_FAST_EXTENSION_ENABLED "CUID#%s - Fast extension enabled."
 #define MSG_EXTENDED_MESSAGING_ENABLED "CUID#%s - Extended Messaging enabled."
 #define MSG_FILE_ALLOCATION_FAILURE                             \
@@ -119,9 +123,9 @@
 #define MSG_DELETING_USED_PIECE _("Deleting used piece index=%d, fillRate(%%)=%d<=%d")
 #define MSG_SELECTIVE_DOWNLOAD_COMPLETED _("Download of selected files was complete.")
 #define MSG_DOWNLOAD_COMPLETED _("The download was complete.")
-#define MSG_REMOVED_HAVE_ENTRY _("Removed %d have entries.")
+#define MSG_REMOVED_HAVE_ENTRY _("Removed %lu have entries.")
 #define MSG_VALIDATING_FILE _("Validating file %s")
-#define MSG_ALLOCATION_COMPLETED _("%d seconds to allocate %s byte(s)")
+#define MSG_ALLOCATION_COMPLETED _("%ld seconds to allocate %s byte(s)")
 #define MSG_FILE_ALLOCATION_DISPATCH                    \
   "Dispatching FileAllocationCommand for CUID#%s."
 #define MSG_METALINK_QUEUEING _("Metalink: Queueing %s for download.")
@@ -141,13 +145,13 @@
 #define MSG_RESOURCE_NOT_FOUND _("Resource not found")
 #define MSG_FILE_RENAMED _("File already exists. Renamed to %s.")
 #define MSG_CANNOT_PARSE_METALINK _("Cannot parse metalink XML file. XML may be malformed.")
-#define MSG_TOO_SMALL_PAYLOAD_SIZE _("Too small payload size for %s, size=%d.")
+#define MSG_TOO_SMALL_PAYLOAD_SIZE _("Too small payload size for %s, size=%lu.")
 #define MSG_REMOVED_DEFUNCT_CONTROL_FILE _("Removed the defunct control file %s because the download file %s doesn't exist.")
 #define MSG_SHARE_RATIO_REPORT _("Your share ratio was %.1f, uploaded/downloaded=%sB/%sB")
 #define MSG_MISSING_BT_INFO _("Missing %s in torrent metainfo.")
 #define MSG_NULL_TRACKER_RESPONSE _("Tracker returned null data.")
 #define MSG_WINSOCK_INIT_FAILD _("Windows socket library initialization failed")
-#define MSG_TIME_HAS_PASSED _("%d second(s) has passed. Stopping application.")
+#define MSG_TIME_HAS_PASSED _("%ld second(s) has passed. Stopping application.")
 #define MSG_SIGNATURE_SAVED _("Saved signature as %s. Please note that aria2" \
                               " doesn't verify signatures.")
 #define MSG_SIGNATURE_NOT_SAVED _("Saving signature as %s failed. Maybe file" \
@@ -247,15 +251,18 @@
 #define EX_SOCKET_PEEK _("Failed to peek data, cause: %s")
 #define EX_SOCKET_UNKNOWN_ERROR _("Unknown socket error %d (0x%x)")
 #define EX_FILE_ALREADY_EXISTS _("File %s exists, but %s does not exist.")
-#define EX_INVALID_PAYLOAD_SIZE _("Invalid payload size for %s, size=%d. It should be %d.")
+#define EX_INVALID_PAYLOAD_SIZE                                 \
+  _("Invalid payload size for %s, size=%lu. It should be %lu.")
 #define EX_INVALID_BT_MESSAGE_ID _("Invalid ID=%d for %s. It should be %d.")
-#define EX_INVALID_CHUNK_CHECKSUM _("Chunk checksum validation failed. checksumIndex=%d, offset=%s, expectedHash=%s, actualHash=%s")
+#define EX_INVALID_CHUNK_CHECKSUM _("Chunk checksum validation failed. checksumIndex=%lu, offset=%s, expectedHash=%s, actualHash=%s")
 #define EX_DOWNLOAD_ABORTED _("Download aborted.")
 #define EX_DUPLICATE_FILE_DOWNLOAD _("File %s is being downloaded by other command.")
 #define EX_INSUFFICIENT_CHECKSUM _("Insufficient checksums.")
 #define EX_TRACKER_FAILURE _("Tracker returned failure reason: %s")
 #define EX_FLOODING_DETECTED _("Flooding detected.")
-#define EX_DROP_INACTIVE_CONNECTION _("Drop connection because no request/piece messages were exchanged in a certain period(%d seconds).")
+#define EX_DROP_INACTIVE_CONNECTION \
+  _("Drop connection because no request/piece messages were exchanged in a" \
+    " certain period(%ld seconds).")
 #define EX_INFOHASH_MISMATCH_IN_SEGFILE _("The infoHash in torrent file doesn't match to one in .aria2 file.")
 #define EX_NO_SUCH_FILE_ENTRY _("No such file entry %s")
 #define EX_TOO_SLOW_DOWNLOAD_SPEED _("Too slow Downloading speed: %d <= %d(B/s), host:%s")