فهرست منبع

Use fmt instead of util::itos

Tatsuhiro Tsujikawa 14 سال پیش
والد
کامیت
1687741303

+ 1 - 1
src/DHTFindNodeReplyMessage.cc

@@ -119,7 +119,7 @@ void DHTFindNodeReplyMessage::setClosestKNodes
 
 std::string DHTFindNodeReplyMessage::toStringOptional() const
 {
-  return "nodes="+util::uitos(closestKNodes_.size());
+  return fmt("nodes=%lu", static_cast<unsigned long>(closestKNodes_.size()));
 }
 
 } // namespace aria2

+ 4 - 4
src/DHTMessageFactoryImpl.cc

@@ -183,8 +183,8 @@ void DHTMessageFactoryImpl::validatePort(const Integer* port) const
 {
   if(!(0 < port->i() && port->i() < UINT16_MAX)) {
     throw DL_ABORT_EX
-      (fmt("Malformed DHT message. Invalid port=%s",
-           util::itos(port->i()).c_str()));
+      (fmt("Malformed DHT message. Invalid port=%lld",
+           static_cast<long long int>(port->i())));
   }
 }
 
@@ -256,8 +256,8 @@ DHTMessageFactoryImpl::createResponseMessage
     // for now, just report error message arrived and throw exception.
     const List* e = getList(dict, DHTUnknownMessage::E);
     if(e->size() == 2) {
-      A2_LOG_INFO(fmt("Received Error DHT message. code=%s, msg=%s",
-                      util::itos(getInteger(e, 0)->i()).c_str(),
+      A2_LOG_INFO(fmt("Received Error DHT message. code=%lld, msg=%s",
+                      static_cast<long long int>(getInteger(e, 0)->i()),
                       util::percentEncode(getString(e, 1)->s()).c_str()));
     } else {
       A2_LOG_DEBUG("e doesn't have 2 elements.");

+ 1 - 1
src/DHTMessageTracker.cc

@@ -87,7 +87,7 @@ DHTMessageTracker::messageArrived
                                           targetNode->getPort());
 
         int64_t rtt = entry->getElapsedMillis();
-        A2_LOG_DEBUG(fmt("RTT is %s", util::itos(rtt).c_str()));
+        A2_LOG_DEBUG(fmt("RTT is %lld", static_cast<long long int>(rtt)));
         message->getRemoteNode()->updateRTT(rtt);
         SharedHandle<DHTMessageCallback> callback = entry->getCallback();
         if(!(*targetNode == *message->getRemoteNode())) {

+ 26 - 24
src/DefaultBtAnnounce.cc

@@ -144,32 +144,33 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
   TransferStat stat = peerStorage_->calculateStat();
   uint64_t left =
     pieceStorage_->getTotalLength()-pieceStorage_->getCompletedLength();
+  // Use last 8 bytes of peer ID as a key
+  const size_t keyLen = 8;
   std::string uri = announceList_.getAnnounce();
   uri += uriHasQuery(uri) ? "&" : "?";
-  uri += "info_hash=";
-  uri += util::torrentPercentEncode(bittorrent::getInfoHash(downloadContext_),
-                                    INFO_HASH_LENGTH);
-  uri += "&peer_id=";
-  uri += util::torrentPercentEncode(bittorrent::getStaticPeerId(),
-                                    PEER_ID_LENGTH);
-  uri += "&uploaded=";
-  uri += util::uitos(stat.getSessionUploadLength());
-  uri += "&downloaded=";
-  uri += util::uitos(stat.getSessionDownloadLength());
-  uri += "&left=";
-  uri += util::uitos(left);
-  uri += "&compact=1";
-  uri += "&key=";
-  // Use last 8 bytes of peer ID as a key
-  size_t keyLen = 8;
-  uri += util::torrentPercentEncode
-    (bittorrent::getStaticPeerId()+PEER_ID_LENGTH-keyLen, keyLen);
-  uri += "&numwant=";
-  uri += util::uitos(numWant);
-  uri += "&no_peer_id=1";
+  uri += fmt("info_hash=%s&"
+             "peer_id=%s&"
+             "uploaded=%lld&"
+             "downloaded=%lld&"
+             "left=%lld&"
+             "compact=1&"
+             "key=%s&"
+             "numwant=%u&"
+             "no_peer_id=1",
+             util::torrentPercentEncode
+             (bittorrent::getInfoHash(downloadContext_),
+              INFO_HASH_LENGTH).c_str(),
+             util::torrentPercentEncode
+             (bittorrent::getStaticPeerId(), PEER_ID_LENGTH).c_str(),
+             static_cast<long long int>(stat.getSessionUploadLength()),
+             static_cast<long long int>(stat.getSessionDownloadLength()),
+             static_cast<long long int>(left),
+             util::torrentPercentEncode
+             (bittorrent::getStaticPeerId()+PEER_ID_LENGTH-keyLen,
+              keyLen).c_str(),
+             numWant);
   if(tcpPort_) {
-    uri += "&port=";
-    uri += util::uitos(tcpPort_);
+    uri += fmt("&port=%u", tcpPort_);
   }
   std::string event = announceList_.getEventString();
   if(!event.empty()) {
@@ -177,7 +178,8 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
     uri += event;
   }
   if(!trackerId_.empty()) {
-    uri += "&trackerid="+util::torrentPercentEncode(trackerId_);
+    uri += "&trackerid=";
+    uri += util::torrentPercentEncode(trackerId_);
   }
   if(option_->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
     uri += "&requirecrypto=1";

+ 3 - 3
src/DefaultBtProgressInfoFile.cc

@@ -277,9 +277,9 @@ void DefaultBtProgressInfoFile::load()
   }
   if(totalLength != dctx_->getTotalLength()) {
     throw DL_ABORT_EX
-      (fmt("total length mismatch. expected: %s, actual: %s",
-           util::itos(dctx_->getTotalLength()).c_str(),
-           util::itos(totalLength).c_str()));
+      (fmt("total length mismatch. expected: %lld, actual: %lld",
+           static_cast<long long int>(dctx_->getTotalLength()),
+           static_cast<long long int>(totalLength)));
   }
   uint64_t uploadLength;
   READ_CHECK(fp, &uploadLength, sizeof(uploadLength));

+ 1 - 1
src/DownloadCommand.cc

@@ -359,7 +359,7 @@ void DownloadCommand::validatePieceHash(const SharedHandle<Segment>& segment,
   } else {
     A2_LOG_INFO(fmt(EX_INVALID_CHUNK_CHECKSUM,
                     static_cast<unsigned long>(segment->getIndex()),
-                    util::itos(segment->getPosition(), true).c_str(),
+                    static_cast<long long int>(segment->getPosition()),
                     util::toHex(expectedHash).c_str(),
                     util::toHex(actualHash).c_str()));
     segment->clear();

+ 1 - 1
src/FileAllocationCommand.cc

@@ -71,7 +71,7 @@ bool FileAllocationCommand::executeInternal()
     A2_LOG_DEBUG
       (fmt(MSG_ALLOCATION_COMPLETED,
            static_cast<long int>(timer_.difference(global::wallclock())),
-           util::itos(getRequestGroup()->getTotalLength(), true).c_str()));
+           static_cast<long long int>(getRequestGroup()->getTotalLength())));
     getDownloadEngine()->getFileAllocationMan()->dropPickedEntry();
     
     std::vector<Command*>* commands = new std::vector<Command*>();

+ 14 - 40
src/FtpConnection.cc

@@ -218,14 +218,11 @@ bool FtpConnection::sendEprt(const SharedHandle<SocketCore>& serverSocket)
     serverSocket->getAddrInfo(sockaddr, len);
     std::pair<std::string, uint16_t> addrinfo =
       util::getNumericNameInfo(&sockaddr.sa, len);
-    std::string request = "EPRT ";
-    request += "|";
-    request += util::itos(sockaddr.storage.ss_family == AF_INET ? 1 : 2);
-    request += "|";
-    request += addrinfo.first;
-    request += "|";
-    request += util::uitos(addrinfo.second);
-    request += "|\r\n";
+    std::string request =
+      fmt("EPRT |%d|%s|%u|\r\n",
+          sockaddr.storage.ss_family == AF_INET ? 1 : 2,
+          addrinfo.first.c_str(),
+          addrinfo.second);
     A2_LOG_INFO(fmt(MSG_SENDING_REQUEST, cuid_, request.c_str()));
     socketBuffer_.pushStr(request);
   }
@@ -242,19 +239,9 @@ bool FtpConnection::sendPort(const SharedHandle<SocketCore>& serverSocket)
     sscanf(addrinfo.first.c_str(), "%u.%u.%u.%u",
            &ipaddr[0], &ipaddr[1], &ipaddr[2], &ipaddr[3]);
     serverSocket->getAddrInfo(addrinfo);
-    std::string request = "PORT ";
-    request += util::uitos(ipaddr[0]);
-    request += ",";
-    request += util::uitos(ipaddr[1]);
-    request += ",";
-    request += util::uitos(ipaddr[2]);
-    request += ",";
-    request += util::uitos(ipaddr[3]);
-    request += ",";
-    request += util::uitos(addrinfo.second/256);
-    request += ",";
-    request += util::uitos(addrinfo.second%256);
-    request += "\r\n";
+    std::string request = fmt("PORT %u,%u,%u,%u,%u,%u\r\n",
+                              ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3],
+                              addrinfo.second/256, addrinfo.second%256);
     A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
                     cuid_, request.c_str()));
     socketBuffer_.pushStr(request);
@@ -266,13 +253,10 @@ bool FtpConnection::sendPort(const SharedHandle<SocketCore>& serverSocket)
 bool FtpConnection::sendRest(const SharedHandle<Segment>& segment)
 {
   if(socketBuffer_.sendBufferIsEmpty()) {
-    std::string request = "REST ";
-    if(!segment) {
-      request += "0";
-    } else {
-      request += util::itos(segment->getPositionToWrite());
-    }
-    request += "\r\n";    
+    std::string request =
+      fmt("REST %lld\r\n",
+          segment ?
+          static_cast<long long int>(segment->getPositionToWrite()) : 0LL);
     A2_LOG_INFO(fmt(MSG_SENDING_REQUEST,
                     cuid_, request.c_str()));
     socketBuffer_.pushStr(request);
@@ -326,11 +310,7 @@ FtpConnection::findEndOfResponse(unsigned int status,
   if(buf.at(3) == '-') {
     // multi line response
     std::string::size_type p;
-
-    std::string endPattern = A2STR::CRLF;
-    endPattern += util::uitos(status);
-    endPattern += " ";
-    p = buf.find(endPattern);
+    p = buf.find(fmt("\r\n%u ", status));
     if(p == std::string::npos) {
       return std::string::npos;
     }
@@ -511,13 +491,7 @@ unsigned int FtpConnection::receivePasvResponse
                "(%u,%u,%u,%u,%u,%u).",
                &h1, &h2, &h3, &h4, &p1, &p2);
         // ip address
-        dest.first = util::uitos(h1);
-        dest.first += A2STR::DOT_C;
-        dest.first += util::uitos(h2);
-        dest.first += A2STR::DOT_C;
-        dest.first += util::uitos(h3);
-        dest.first += A2STR::DOT_C;
-        dest.first += util::uitos(h4);
+        dest.first = fmt("%u.%u.%u.%u", h1, h2, h3, h4);
         // port number
         dest.second = 256*p1+p2;
       } else {

+ 1 - 2
src/FtpNegotiationCommand.cc

@@ -471,8 +471,7 @@ bool FtpNegotiationCommand::recvSize() {
 
     if(size > INT64_MAX) {
       throw DL_ABORT_EX2
-        (fmt(EX_TOO_LARGE_FILE,
-             util::uitos(size, true).c_str()),
+        (fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(size)),
          error_code::FTP_PROTOCOL_ERROR);
     }
     if(!getPieceStorage()) {

+ 2 - 3
src/HttpRequest.cc

@@ -193,9 +193,8 @@ std::string HttpRequest::createRequest()
   }
   if(segment_ && segment_->getLength() > 0 && 
      (request_->isPipeliningEnabled() || getStartByte() > 0)) {
-    std::string rangeHeader = "bytes=";
-    rangeHeader += util::itos(getStartByte());
-    rangeHeader += "-";
+    std::string rangeHeader(fmt("bytes=%lld-",
+                                static_cast<long long int>(getStartByte())));
     if(request_->isPipeliningEnabled()) {
       rangeHeader += util::itos(getEndByte());
     } else if(getProtocol() != Request::PROTO_FTP && endOffsetOverride_ > 0) {

+ 6 - 6
src/HttpResponse.cc

@@ -100,12 +100,12 @@ void HttpResponse::validateResponse() const
       if(!httpRequest_->isRangeSatisfied(responseRange)) {
         throw DL_ABORT_EX2
           (fmt(EX_INVALID_RANGE_HEADER,
-               util::itos(httpRequest_->getStartByte(), true).c_str(),
-               util::itos(httpRequest_->getEndByte(), true).c_str(),
-               util::uitos(httpRequest_->getEntityLength(), true).c_str(),
-               util::itos(responseRange->getStartByte(), true).c_str(),
-               util::itos(responseRange->getEndByte(), true).c_str(),
-               util::uitos(responseRange->getEntityLength(), true).c_str()),
+               static_cast<long long int>(httpRequest_->getStartByte()),
+               static_cast<long long int>(httpRequest_->getEndByte()),
+               static_cast<long long int>(httpRequest_->getEntityLength()),
+               static_cast<long long int>(responseRange->getStartByte()),
+               static_cast<long long int>(responseRange->getEndByte()),
+               static_cast<long long int>(responseRange->getEntityLength())),
            error_code::CANNOT_RESUME);
       }
     }

+ 5 - 4
src/HttpServerCommand.cc

@@ -136,10 +136,11 @@ bool HttpServerCommand::execute()
       if(static_cast<uint64_t>
          (e_->getOption()->getAsInt(PREF_RPC_MAX_REQUEST_SIZE)) <
          httpServer_->getContentLength()) {
-        A2_LOG_INFO(fmt("Request too long. ContentLength=%s."
-                        " See --rpc-max-request-size option to loose"
-                        " this limitation.",
-                        util::uitos(httpServer_->getContentLength()).c_str()));
+        A2_LOG_INFO
+          (fmt("Request too long. ContentLength=%lld."
+               " See --rpc-max-request-size option to loose"
+               " this limitation.",
+               static_cast<long long int>(httpServer_->getContentLength())));
         return true;
       }
       Command* command = new HttpServerBodyCommand(getCuid(), httpServer_, e_,

+ 1 - 1
src/IteratableChunkChecksumValidator.cc

@@ -78,7 +78,7 @@ void IteratableChunkChecksumValidator::validateChunk()
         A2_LOG_INFO
           (fmt(EX_INVALID_CHUNK_CHECKSUM,
                static_cast<unsigned long>(currentIndex_),
-               util::itos(getCurrentOffset(), true).c_str(),
+               static_cast<long long int>(getCurrentOffset()),
                util::toHex(dctx_->getPieceHashes()[currentIndex_]).c_str(),
                util::toHex(actualChecksum).c_str()));
         bitfield_->unsetBit(currentIndex_);

+ 3 - 4
src/MultiDiskAdaptor.cc

@@ -348,8 +348,7 @@ DiskWriterEntries::const_iterator findFirstDiskWriterEntry
   // In case when offset is out-of-range
   if(!isInRange(*first, offset)) {
     throw DL_ABORT_EX
-      (fmt(EX_FILE_OFFSET_OUT_OF_RANGE,
-           util::itos(offset, true).c_str()));
+      (fmt(EX_FILE_OFFSET_OUT_OF_RANGE, static_cast<long long int>(offset)));
   }
   return first;
 }
@@ -360,8 +359,8 @@ void throwOnDiskWriterNotOpened(const SharedHandle<DiskWriterEntry>& e,
                                 off_t offset)
 {
   throw DL_ABORT_EX
-    (fmt("DiskWriter for offset=%s, filename=%s is not opened.",
-         util::itos(offset).c_str(),
+    (fmt("DiskWriter for offset=%lld, filename=%s is not opened.",
+         static_cast<long long int>(offset),
          e->getFilePath().c_str()));  
 }
 } // namespace

+ 10 - 11
src/OptionHandlerImpl.cc

@@ -125,9 +125,8 @@ void IntegerRangeOptionHandler::parseArg
     if(v < min_ || max_ < v) {
       std::string msg = pref_->k;
       msg += " ";
-      msg += _("must be between %s and %s.");
-      throw DL_ABORT_EX
-        (fmt(msg.c_str(), util::itos(min_).c_str(), util::itos(max_).c_str()));
+      msg += _("must be between %d and %d.");
+      throw DL_ABORT_EX(fmt(msg.c_str(), min_, max_));
     }
     option.put(pref_, optarg);
   }
@@ -135,7 +134,7 @@ void IntegerRangeOptionHandler::parseArg
 
 std::string IntegerRangeOptionHandler::createPossibleValuesString() const
 {
-  return util::itos(min_)+"-"+util::itos(max_);
+  return fmt("%d-%d", min_, max_);
 }
 
 NumberOptionHandler::NumberOptionHandler
@@ -166,15 +165,15 @@ void NumberOptionHandler::parseArg(Option& option, int64_t number)
     std::string msg = pref_->k;
     msg += " ";
     if(min_ == -1 && max_ != -1) {
-      msg += fmt(_("must be smaller than or equal to %s."),
-                 util::itos(max_).c_str());
+      msg += fmt(_("must be smaller than or equal to %lld."),
+                 static_cast<long long int>(max_));
     } else if(min_ != -1 && max_ != -1) {
-      msg += fmt(_("must be between %s and %s."),
-                 util::itos(min_).c_str(),
-                 util::itos(max_).c_str());
+      msg += fmt(_("must be between %lld and %lld."),
+                 static_cast<long long int>(min_),
+                 static_cast<long long int>(max_));
     } else if(min_ != -1 && max_ == -1) {
-      msg += fmt(_("must be greater than or equal to %s."),
-                 util::itos(min_).c_str());
+      msg += fmt(_("must be greater than or equal to %lld."),
+                 static_cast<long long int>(min_));
     } else {
       msg += _("must be a number.");
     }

+ 1 - 1
src/PeerReceiveHandshakeCommand.cc

@@ -156,7 +156,7 @@ bool PeerReceiveHandshakeCommand::executeInternal()
         getDownloadEngine()->addCommand(command);
         A2_LOG_DEBUG(fmt(MSG_INCOMING_PEER_CONNECTION,
                          getCuid(),
-                         util::itos(getPeer()->usedBy()).c_str()));
+                         getPeer()->usedBy()));
       }
     }
     return true;

+ 6 - 8
src/RequestGroup.cc

@@ -404,9 +404,9 @@ void RequestGroup::createInitialCommand
           // truncate the file to downloadContext_->getTotalLength()
           A2_LOG_DEBUG
             (fmt("File size not match. File is opened in writable"
-                 " mode. Expected:%s Actual:%s",
-                 util::uitos(downloadContext_->getTotalLength()).c_str(),
-                 util::uitos(actualFileSize).c_str()));
+                 " mode. Expected:%lld Actual:%lld",
+                 static_cast<long long int>(downloadContext_->getTotalLength()),
+                 static_cast<long long int>(actualFileSize)));
         }
       }
       // Call Load, Save and file allocation command here
@@ -793,9 +793,7 @@ bool RequestGroup::tryAutoFileRenaming()
     return false;
   }
   for(unsigned int i = 1; i < 10000; ++i) {
-    std::string newfilename = filepath;
-    newfilename += ".";
-    newfilename += util::uitos(i);
+    std::string newfilename = fmt("%s.%u", filepath.c_str(), i);
     File newfile(newfilename);
     File ctrlfile(newfile.getPath()+DefaultBtProgressInfoFile::getSuffix());
     if(!newfile.exists() || (newfile.exists() && ctrlfile.exists())) {
@@ -917,8 +915,8 @@ void RequestGroup::validateTotalLength(uint64_t expectedTotalLength,
   if(expectedTotalLength != actualTotalLength) {
     throw DL_ABORT_EX
       (fmt(EX_SIZE_MISMATCH,
-           util::itos(expectedTotalLength, true).c_str(),
-           util::itos(actualTotalLength, true).c_str()));
+           static_cast<long long int>(expectedTotalLength),
+           static_cast<long long int>(actualTotalLength)));
   }
 }
 

+ 3 - 3
src/SegmentMan.cc

@@ -470,10 +470,10 @@ size_t SegmentMan::countFreePieceFrom(size_t index) const
 
 void SegmentMan::ignoreSegmentFor(const SharedHandle<FileEntry>& fileEntry)
 {
-  A2_LOG_DEBUG(fmt("ignoring segment for path=%s, offset=%s, length=%s",
+  A2_LOG_DEBUG(fmt("ignoring segment for path=%s, offset=%lld, length=%lld",
                    fileEntry->getPath().c_str(),
-                   util::itos(fileEntry->getOffset()).c_str(),
-                   util::uitos(fileEntry->getLength()).c_str()));
+                   static_cast<long long int>(fileEntry->getOffset()),
+                   static_cast<long long int>(fileEntry->getLength())));
   ignoreBitfield_.addFilter(fileEntry->getOffset(), fileEntry->getLength());
 }
 

+ 2 - 3
src/TrackerWatcherCommand.cc

@@ -175,9 +175,8 @@ void TrackerWatcherCommand::processTrackerResponse
     command->setPeerStorage(peerStorage_);
     command->setPieceStorage(pieceStorage_);
     e_->addCommand(command);
-    A2_LOG_DEBUG(fmt("CUID#%lld - Adding new command CUID#%s",
-                     getCuid(),
-                     util::itos(peer->usedBy()).c_str()));
+    A2_LOG_DEBUG(fmt("CUID#%lld - Adding new command CUID#%lld",
+                     getCuid(), peer->usedBy()));
   }
 }
 

+ 7 - 7
src/message.h

@@ -95,7 +95,7 @@
   "CUID#%lld - Using port %d for accepting new connections"
 #define MSG_BIND_FAILURE "CUID#%lld - An error occurred while binding port=%d"
 #define MSG_INCOMING_PEER_CONNECTION                            \
-  "CUID#%lld - Incoming connection, adding new command CUID#%s"
+  "CUID#%lld - Incoming connection, adding new command CUID#%lld"
 #define MSG_ACCEPT_FAILURE "CUID#%lld - Error in accepting connection"
 #define MSG_TRACKER_RESPONSE_PROCESSING_FAILED                  \
   "CUID#%lld - Error occurred while processing tracker response."
@@ -125,7 +125,7 @@
 #define MSG_DOWNLOAD_COMPLETED _("The download was complete.")
 #define MSG_REMOVED_HAVE_ENTRY _("Removed %lu have entries.")
 #define MSG_VALIDATING_FILE _("Validating file %s")
-#define MSG_ALLOCATION_COMPLETED _("%ld seconds to allocate %s byte(s)")
+#define MSG_ALLOCATION_COMPLETED "%ld seconds to allocate %lld byte(s)"
 #define MSG_FILE_ALLOCATION_DISPATCH                    \
   "Dispatching FileAllocationCommand for CUID#%lld."
 #define MSG_METALINK_QUEUEING _("Metalink: Queueing %s for download.")
@@ -207,14 +207,14 @@
 #define EX_CONNECTION_FAILED _("Connection failed.")
 #define EX_FILENAME_MISMATCH _("The requested filename and the previously registered one are not same. Expected:%s Actual:%s")
 #define EX_BAD_STATUS _("The response status is not successful. status=%d")
-#define EX_TOO_LARGE_FILE _("Too large file size. size=%s")
+#define EX_TOO_LARGE_FILE "Too large file size. size=%lld"
 #define EX_TRANSFER_ENCODING_NOT_SUPPORTED _("Transfer encoding %s is not supported.")
 #define EX_SSL_INIT_FAILURE _("SSL initialization failed: %s")
 #define EX_SSL_IO_ERROR _("SSL I/O error")
 #define EX_SSL_PROTOCOL_ERROR _("SSL protocol error")
 #define EX_SSL_UNKNOWN_ERROR _("SSL unknown error %d")
 #define EX_SSL_CONNECT_ERROR _("SSL initialization failed: OpenSSL connect error %d")
-#define EX_SIZE_MISMATCH _("Size mismatch Expected:%s Actual:%s")
+#define EX_SIZE_MISMATCH "Size mismatch Expected:%lld Actual:%lld"
 #define EX_AUTH_FAILED _("Authorization failed.")
 #define EX_GOT_EOF _("Got EOF from the server.")
 #define EX_EOF_FROM_PEER _("Got EOF from peer.")
@@ -226,7 +226,7 @@
 #define EX_DATA_READ _("Failed to read data from disk.")
 #define EX_FILE_SHA1SUM _("Failed to calculate SHA1 digest of or a part of the file %s, cause: %s")
 #define EX_FILE_SEEK _("Failed to seek the file %s, cause: %s")
-#define EX_FILE_OFFSET_OUT_OF_RANGE _("The offset is out of range, offset=%s")
+#define EX_FILE_OFFSET_OUT_OF_RANGE "The offset is out of range, offset=%lld"
 #define EX_NOT_DIRECTORY _("%s is not a directory.")
 #define EX_MAKE_DIR _("Failed to make the directory %s, cause: %s")
 #define EX_SEGMENT_FILE_WRITE "Failed to write into the segment file %s"
@@ -253,7 +253,7 @@
 #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=%lu, offset=%s, expectedHash=%s, actualHash=%s")
+#define EX_INVALID_CHUNK_CHECKSUM "Chunk checksum validation failed. checksumIndex=%lu, offset=%lld, 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.")
@@ -267,7 +267,7 @@
 #define EX_TOO_SLOW_DOWNLOAD_SPEED _("Too slow Downloading speed: %d <= %d(B/s), host:%s")
 #define EX_NO_HTTP_REQUEST_ENTRY_FOUND _("No HttpRequestEntry found.")
 #define EX_LOCATION_HEADER_REQUIRED _("Got %d status, but no location header provided.")
-#define EX_INVALID_RANGE_HEADER _("Invalid range header. Request: %s-%s/%s, Response: %s-%s/%s")
+#define EX_INVALID_RANGE_HEADER "Invalid range header. Request: %lld-%lld/%lld, Response: %lld-%lld/%lld"
 #define EX_NO_RESULT_WITH_YOUR_PREFS _("No file matched with your preference.")
 #define EX_EXCEPTION_CAUGHT _("Exception caught")
 #define EX_TOO_LONG_PAYLOAD _("Max payload length exceeded or invalid. length = %u")

+ 3 - 7
src/util.cc

@@ -1087,20 +1087,16 @@ std::string abbrevSize(int64_t size)
   if(size < 1024) {
     return itos(size, true);
   }
-  char units[] = { 'K', 'M' };
-  size_t numUnit = sizeof(units)/sizeof(char);
+  static const char units[] = { 'K', 'M' };
   size_t i = 0;
   int r = size&0x3ffu;
   size >>= 10;
-  for(; i < numUnit-1 && size >= 1024; ++i) {
+  for(; i < sizeof(units)-1 && size >= 1024; ++i) {
     r = size&0x3ffu;
     size >>= 10;
   }
   std::string result = itos(size, true);
-  result += A2STR::DOT_C;
-  result += itos(r*10/1024);
-  result += units[i];
-  result += "i";
+  result += fmt(".%d%ci", r*10/1024, units[i]);
   return result;
 }