Pārlūkot izejas kodu

New round of clang-modernize

Nils Maier 11 gadi atpakaļ
vecāks
revīzija
b9fe4119c0

+ 2 - 2
src/AdaptiveURISelector.cc

@@ -66,8 +66,8 @@ namespace aria2 {
  */
 
 AdaptiveURISelector::AdaptiveURISelector
-(const std::shared_ptr<ServerStatMan>& serverStatMan, RequestGroup* requestGroup)
-  : serverStatMan_(serverStatMan),
+(std::shared_ptr<ServerStatMan> serverStatMan, RequestGroup* requestGroup)
+  : serverStatMan_(std::move(serverStatMan)),
     requestGroup_(requestGroup)
 {
   resetCounters();

+ 1 - 1
src/AdaptiveURISelector.h

@@ -71,7 +71,7 @@ private:
   int getNbTestedServers(const std::deque<std::string>& uris) const;
   std::string getBestMirror(const std::deque<std::string>& uris) const;
 public:
-  AdaptiveURISelector(const std::shared_ptr<ServerStatMan>& serverStatMan,
+  AdaptiveURISelector(std::shared_ptr<ServerStatMan> serverStatMan,
                       RequestGroup* requestGroup);
 
   virtual ~AdaptiveURISelector();

+ 1 - 1
src/BtBitfieldMessage.cc

@@ -108,7 +108,7 @@ unsigned char* BtBitfieldMessage::createMessage() {
    * total: 5+bitfieldLength bytes
    */
   const size_t msgLength = 5+bitfieldLength_;
-  auto msg = new unsigned char[msgLength];
+  auto   msg = new unsigned char[msgLength];
   bittorrent::createPeerMessageString(msg, msgLength, 1+bitfieldLength_, ID);
   memcpy(msg+5, bitfield_, bitfieldLength_);
   return msg;

+ 3 - 1
src/ColorizedStream.h

@@ -40,6 +40,8 @@
 #include <sstream>
 #include <deque>
 
+#include "config.h"
+
 namespace aria2 {
 
 namespace colors {
@@ -105,7 +107,7 @@ public:
     elems.push_back(std::make_pair(eString, ""));
   }
 
-  traits_t::int_type overflow(traits_t::int_type c)
+  traits_t::int_type overflow(traits_t::int_type c) CXX11_OVERRIDE
   {
     elems.back().second.push_back((char)c);
     return std::char_traits<char>::not_eof(c);

+ 1 - 1
src/DNSCache.h

@@ -114,7 +114,7 @@ public:
   (OutputIterator out, const std::string& hostname, uint16_t port) const
   {
     std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
-    CacheEntrySet::iterator i = entries_.find(target);
+    auto i = entries_.find(target);
     if(i != entries_.end()) {
       (*i)->getAllGoodAddrs(out);
     }

+ 2 - 2
src/Event.h

@@ -314,9 +314,9 @@ private:
   sock_t sockets_[ARES_GETSOCK_MAXNUM];
 
 public:
-  AsyncNameResolverEntry(const std::shared_ptr<AsyncNameResolver>& nameResolver,
+  AsyncNameResolverEntry(std::shared_ptr<AsyncNameResolver> nameResolver,
                          Command* command):
-    nameResolver_(nameResolver), command_(command), socketsSize_(0) {}
+    nameResolver_(std::move(nameResolver)), command_(command), socketsSize_(0) {}
 
   bool operator==(const AsyncNameResolverEntry& entry)
   {

+ 2 - 2
src/HashFuncEntry.h

@@ -50,8 +50,8 @@ struct HashFuncEntry {
   typedef HashFunc HashFuncType;
   std::string hashType;
   HashFunc hashFunc;
-  HashFuncEntry(const std::string& hashType, const HashFunc& hashFunc):
-    hashType(hashType), hashFunc(hashFunc)
+  HashFuncEntry(std::string hashType, const HashFunc& hashFunc):
+    hashType(std::move(hashType)), hashFunc(hashFunc)
   {}
 };
 

+ 3 - 3
src/LibgcryptARC4Encryptor.cc

@@ -51,7 +51,7 @@ void handleError(gcry_error_t err)
 } // namespace
 
 ARC4Encryptor::ARC4Encryptor()
-  : hdl_(0)
+  : hdl_(nullptr)
 {}
 
 ARC4Encryptor::~ARC4Encryptor()
@@ -71,7 +71,7 @@ void ARC4Encryptor::init(const unsigned char* key, size_t keyLength)
   if((r = gcry_cipher_setkey(hdl_, key, keyLength))) {
     handleError(r);
   }
-  if((r = gcry_cipher_setiv(hdl_, 0, 0))) {
+  if((r = gcry_cipher_setiv(hdl_, nullptr, 0))) {
     handleError(r);
   }
 }
@@ -84,7 +84,7 @@ void ARC4Encryptor::encrypt
   size_t inlen;
   if(in == out) {
     out = const_cast<unsigned char*>(in);
-    in = 0;
+    in = nullptr;
     inlen = 0;
   } else {
     inlen = len;

+ 7 - 7
src/LibgcryptDHKeyExchange.cc

@@ -49,10 +49,10 @@ void handleError(gcry_error_t err)
 
 DHKeyExchange::DHKeyExchange()
   : keyLength_(0),
-    prime_(0),
-    generator_(0),
-    privateKey_(0),
-    publicKey_(0)
+    prime_(nullptr),
+    generator_(nullptr),
+    privateKey_(nullptr),
+    publicKey_(nullptr)
 {}
 
 DHKeyExchange::~DHKeyExchange()
@@ -72,14 +72,14 @@ void DHKeyExchange::init(const unsigned char* prime, size_t primeBits,
   gcry_mpi_release(privateKey_);
   {
     gcry_error_t r = gcry_mpi_scan(&prime_, GCRYMPI_FMT_HEX,
-                                   prime, 0, 0);
+                                   prime, 0, nullptr);
     if(r) {
       handleError(r);
     }
   }
   {
     gcry_error_t r = gcry_mpi_scan(&generator_, GCRYMPI_FMT_HEX,
-                                   generator, 0, 0);
+                                   generator, 0, nullptr);
     if(r) {
       handleError(r);
     }
@@ -137,7 +137,7 @@ size_t DHKeyExchange::computeSecret(unsigned char* out, size_t outLength,
                                    GCRYMPI_FMT_USG,
                                    peerPublicKeyData,
                                    peerPublicKeyLength,
-                                   0);
+                                   nullptr);
     if(r) {
       handleError(r);
     }

+ 2 - 2
src/LibgnutlsTLSSession.cc

@@ -48,7 +48,7 @@ TLSSession* TLSSession::make(TLSContext* ctx)
 }
 
 GnuTLSSession::GnuTLSSession(GnuTLSContext* tlsContext)
-  : sslSession_(0),
+  : sslSession_(nullptr),
     tlsContext_(tlsContext),
     rv_(0)
 {}
@@ -265,7 +265,7 @@ int GnuTLSSession::tlsConnect(const std::string& hostname,
     for(int i = 0; !(ret < 0); ++i) {
       altNameLen = sizeof(altName);
       ret = gnutls_x509_crt_get_subject_alt_name(cert, i, altName,
-                                                 &altNameLen, 0);
+                                                 &altNameLen, nullptr);
       if(ret == GNUTLS_SAN_DNSNAME) {
         dnsNames.push_back(std::string(altName, altNameLen));
       } else if(ret == GNUTLS_SAN_IPADDRESS) {

+ 10 - 10
src/LibsslDHKeyExchange.cc

@@ -49,17 +49,17 @@ void handleError(const std::string& funName)
 {
   throw DL_ABORT_EX
     (fmt("Exception in libssl routine %s(DHKeyExchange class): %s",
-         funName.c_str(), ERR_error_string(ERR_get_error(), 0)));
+         funName.c_str(), ERR_error_string(ERR_get_error(), nullptr)));
 }
 } // namespace
 
 DHKeyExchange::DHKeyExchange()
-  : bnCtx_(0),
+  : bnCtx_(nullptr),
     keyLength_(0),
-    prime_(0),
-    generator_(0),
-    privateKey_(0),
-    publicKey_(0)
+    prime_(nullptr),
+    generator_(nullptr),
+    privateKey_(nullptr),
+    publicKey_(nullptr)
 {}
 
 DHKeyExchange::~DHKeyExchange()
@@ -82,11 +82,11 @@ void DHKeyExchange::init(const unsigned char* prime, size_t primeBits,
   }
 
   BN_free(prime_);
-  prime_ = 0;
+  prime_ = nullptr;
   BN_free(generator_);
-  generator_ = 0;
+  generator_ = nullptr;
   BN_free(privateKey_);
-  privateKey_ = 0;
+  privateKey_ = nullptr;
 
   if(BN_hex2bn(&prime_, reinterpret_cast<const char*>(prime)) == 0) {
     handleError("BN_hex2bn in init");
@@ -150,7 +150,7 @@ size_t DHKeyExchange::computeSecret(unsigned char* out, size_t outLength,
   }
 
 
-  BIGNUM* peerPublicKey = BN_bin2bn(peerPublicKeyData, peerPublicKeyLength, 0);
+  BIGNUM* peerPublicKey = BN_bin2bn(peerPublicKeyData, peerPublicKeyLength, nullptr);
   if(!peerPublicKey) {
     handleError("BN_bin2bn in computeSecret");
   }

+ 1 - 1
src/LibsslMessageDigestImpl.cc

@@ -57,7 +57,7 @@ public:
     return len_;
   }
   virtual void reset() CXX11_OVERRIDE {
-    EVP_DigestInit_ex(&ctx_, md_, 0);
+    EVP_DigestInit_ex(&ctx_, md_, nullptr);
   }
   virtual void update(const void* data, size_t length) CXX11_OVERRIDE {
     auto bytes = reinterpret_cast<const char*>(data);

+ 8 - 8
src/LibsslTLSContext.cc

@@ -87,7 +87,7 @@ TLSContext* TLSContext::make(TLSSessionSide side)
 }
 
 OpenSSLTLSContext::OpenSSLTLSContext(TLSSessionSide side)
-  : sslCtx_(0),
+  : sslCtx_(nullptr),
     side_(side),
     verifyPeer_(true)
 {
@@ -97,7 +97,7 @@ OpenSSLTLSContext::OpenSSLTLSContext(TLSSessionSide side)
   } else {
     good_ = false;
     A2_LOG_ERROR(fmt("SSL_CTX_new() failed. Cause: %s",
-                     ERR_error_string(ERR_get_error(), 0)));
+                     ERR_error_string(ERR_get_error(), nullptr)));
     return;
   }
   // Disable SSLv2 and enable all workarounds for buggy servers
@@ -139,13 +139,13 @@ bool OpenSSLTLSContext::addCredentialFile(const std::string& certfile,
                                  SSL_FILETYPE_PEM) != 1) {
     A2_LOG_ERROR(fmt("Failed to load private key from %s. Cause: %s",
                      keyfile.c_str(),
-                     ERR_error_string(ERR_get_error(), 0)));
+                     ERR_error_string(ERR_get_error(), nullptr)));
     return false;
   }
   if(SSL_CTX_use_certificate_chain_file(sslCtx_, certfile.c_str()) != 1) {
     A2_LOG_ERROR(fmt("Failed to load certificate from %s. Cause: %s",
                      certfile.c_str(),
-                     ERR_error_string(ERR_get_error(), 0)));
+                     ERR_error_string(ERR_get_error(), nullptr)));
     return false;
   }
   A2_LOG_INFO(fmt("Credential files(cert=%s, key=%s) were successfully added.",
@@ -177,7 +177,7 @@ bool OpenSSLTLSContext::addP12CredentialFile(const std::string& p12file)
   }
   EVP_PKEY *pkey;
   X509 *cert;
-  STACK_OF(X509) *ca = 0;
+  STACK_OF(X509) *ca = nullptr;
   if (!PKCS12_parse(p12.get(), "", &pkey, &cert, &ca)) {
     A2_LOG_ERROR(fmt("Failed to parse PKCS12 file: %s. "
                      "If you meant to use PEM, you'll also have to specify "
@@ -219,7 +219,7 @@ bool OpenSSLTLSContext::addSystemTrustedCACerts()
 {
   if(SSL_CTX_set_default_verify_paths(sslCtx_) != 1) {
     A2_LOG_INFO(fmt(MSG_LOADING_SYSTEM_TRUSTED_CA_CERTS_FAILED,
-                    ERR_error_string(ERR_get_error(), 0)));
+                    ERR_error_string(ERR_get_error(), nullptr)));
     return false;
   } else {
     A2_LOG_INFO("System trusted CA certificates were successfully added.");
@@ -229,10 +229,10 @@ bool OpenSSLTLSContext::addSystemTrustedCACerts()
 
 bool OpenSSLTLSContext::addTrustedCACertFile(const std::string& certfile)
 {
-  if(SSL_CTX_load_verify_locations(sslCtx_, certfile.c_str(), 0) != 1) {
+  if(SSL_CTX_load_verify_locations(sslCtx_, certfile.c_str(), nullptr) != 1) {
     A2_LOG_ERROR(fmt(MSG_LOADING_TRUSTED_CA_CERT_FAILED,
                      certfile.c_str(),
-                     ERR_error_string(ERR_get_error(), 0)));
+                     ERR_error_string(ERR_get_error(), nullptr)));
     return false;
   } else {
     A2_LOG_INFO("Trusted CA certificates were successfully added.");

+ 3 - 3
src/LibsslTLSSession.cc

@@ -50,7 +50,7 @@ TLSSession* TLSSession::make(TLSContext* ctx)
 }
 
 OpenSSLTLSSession::OpenSSLTLSSession(OpenSSLTLSContext* tlsContext)
-  : ssl_(0),
+  : ssl_(nullptr),
     tlsContext_(tlsContext),
     rv_(1)
 {}
@@ -205,7 +205,7 @@ int OpenSSLTLSSession::tlsConnect(const std::string& hostname,
     std::vector<std::string> ipAddrs;
     GENERAL_NAMES* altNames;
     altNames = reinterpret_cast<GENERAL_NAMES*>
-      (X509_get_ext_d2i(peerCert, NID_subject_alt_name, NULL, NULL));
+      (X509_get_ext_d2i(peerCert, NID_subject_alt_name, nullptr, NULL));
     if(altNames) {
       std::unique_ptr<GENERAL_NAMES, decltype(&GENERAL_NAMES_free)>
         altNamesDeleter(altNames, GENERAL_NAMES_free);
@@ -289,7 +289,7 @@ std::string OpenSSLTLSSession::getLastErrorString()
           return "unknown syscall error";
         }
       } else {
-        return ERR_error_string(err, 0);
+        return ERR_error_string(err, nullptr);
       }
     }
     case SSL_ERROR_SSL:

+ 1 - 1
src/Netrc.cc

@@ -228,7 +228,7 @@ class AuthHostMatch {
 private:
   std::string hostname;
 public:
-  AuthHostMatch(const std::string& hostname):hostname(hostname) {}
+  AuthHostMatch(std::string hostname) : hostname(std::move(hostname)) {}
 
   bool operator()(const std::unique_ptr<Authenticator>& authenticator)
   {

+ 2 - 2
src/OptionHandlerFactory.cc

@@ -869,9 +869,9 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
     handlers.push_back(op);
   }
   {
-    DefaultOptionHandler* op(new DefaultOptionHandler
+    auto op = new DefaultOptionHandler
                              (PREF_RPC_SECRET,
-                              TEXT_RPC_SECRET));
+                              TEXT_RPC_SECRET);
     op->addTag(TAG_RPC);
     op->setEraseAfterParse(true);
     op->setAllowEmpty(false);

+ 1 - 1
src/Peer.cc

@@ -46,7 +46,7 @@
 namespace aria2 {
 
 Peer::Peer(std::string ipaddr, uint16_t port, bool incoming):
-  ipaddr_(ipaddr),
+  ipaddr_(std::move(ipaddr)),
   port_(port),
   origPort_(port),
   cuid_(0),

+ 2 - 2
src/RequestSlot.h

@@ -45,10 +45,10 @@ namespace aria2 {
 class RequestSlot {
 public:
   RequestSlot(size_t index, int32_t begin, int32_t length, size_t blockIndex,
-              const std::shared_ptr<Piece>& piece = nullptr)
+              std::shared_ptr<Piece> piece = nullptr)
     : dispatchedTime_(global::wallclock()),
       index_(index), begin_(begin), length_(length), blockIndex_(blockIndex),
-      piece_(piece)
+      piece_(std::move(piece))
   {}
 
   RequestSlot():dispatchedTime_(0), index_(0), begin_(0), length_(0),

+ 1 - 1
src/SegmentMan.cc

@@ -347,7 +347,7 @@ class FindSegmentEntry {
 private:
   std::shared_ptr<Segment> segment_;
 public:
-  FindSegmentEntry(const std::shared_ptr<Segment>& segment):segment_(segment) {}
+  FindSegmentEntry(std::shared_ptr<Segment> segment):segment_(std::move(segment)) {}
 
   bool operator()(const std::shared_ptr<SegmentEntry>& segmentEntry) const
   {

+ 4 - 4
src/UDPTrackerClient.cc

@@ -122,8 +122,8 @@ struct CollectAddrPortMatch {
   std::string remoteAddr;
   uint16_t remotePort;
   CollectAddrPortMatch(std::vector<std::shared_ptr<UDPTrackerRequest> >& dest,
-                       const std::string& remoteAddr, uint16_t remotePort)
-    : dest(dest), remoteAddr(remoteAddr), remotePort(remotePort)
+                       std::string remoteAddr, uint16_t remotePort)
+    : dest(dest), remoteAddr(std::move(remoteAddr)), remotePort(remotePort)
   {}
 };
 } // namespace
@@ -501,9 +501,9 @@ struct FailConnectDelete {
   std::string remoteAddr;
   uint16_t remotePort;
   int error;
-  FailConnectDelete(const std::string& remoteAddr, uint16_t remotePort,
+  FailConnectDelete(std::string remoteAddr, uint16_t remotePort,
                     int error)
-    : remoteAddr(remoteAddr), remotePort(remotePort), error(error)
+    : remoteAddr(std::move(remoteAddr)), remotePort(remotePort), error(error)
   {}
 };
 } // namespace

+ 4 - 5
src/aria2api.cc

@@ -522,9 +522,8 @@ std::vector<A2Gid> getActiveDownload(Session* session)
   auto& e = session->context->reqinfo->getDownloadEngine();
   const RequestGroupList& groups = e->getRequestGroupMan()->getRequestGroups();
   std::vector<A2Gid> res;
-  for(RequestGroupList::const_iterator i = groups.begin(),
-        eoi = groups.end(); i != eoi; ++i) {
-    res.push_back((*i)->getGID());
+  for(const auto& group : groups) {
+    res.push_back(group->getGID());
   }
   return res;
 }
@@ -815,8 +814,8 @@ struct RequestGroupDH : public DownloadHandle {
 
 namespace {
 struct DownloadResultDH : public DownloadHandle {
-  DownloadResultDH(const std::shared_ptr<DownloadResult>& dr)
-    : dr(dr)
+  DownloadResultDH(std::shared_ptr<DownloadResult> dr)
+    : dr(std::move(dr))
   {}
   virtual ~DownloadResultDH() {}
   virtual DownloadStatus getStatus() CXX11_OVERRIDE

+ 3 - 3
src/daemon.cc

@@ -65,13 +65,13 @@ int daemon(int nochdir, int noclose)
     }
   }
   if(noclose == 0) {
-    if(freopen("/dev/null", "r", stdin) == 0) {
+    if(freopen("/dev/null", "r", stdin) == nullptr) {
       return -1;
     }
-    if(freopen("/dev/null", "w", stdout) == 0) {
+    if(freopen("/dev/null", "w", stdout) == nullptr) {
       return -1;
     }
-    if(freopen("/dev/null", "w", stderr) == 0) {
+    if(freopen("/dev/null", "w", stderr) == nullptr) {
       return -1;
     }
   }

+ 2 - 2
src/download_helper.cc

@@ -332,10 +332,10 @@ private:
   bool throwOnError_;
 public:
   AccRequestGroup(std::vector<std::shared_ptr<RequestGroup>>& requestGroups,
-                  const std::shared_ptr<Option>& option,
+                  std::shared_ptr<Option> option,
                   bool ignoreLocalPath = false,
                   bool throwOnError = false):
-    requestGroups_(requestGroups), option_(option),
+    requestGroups_(requestGroups), option_(std::move(option)),
     ignoreLocalPath_(ignoreLocalPath),
     throwOnError_(throwOnError)
   {}