Merge #19314: refactor: Use uint16_t instead of unsigned short

1cabbddbca refactor: Use uint16_t instead of unsigned short (Aaron Hook)

Pull request description:

  I wanted to see if the `up for grabs` label works and looked at PR #17822 originally opend by ahook I saw it had many acks for example by jonatack and practicalswift but needed rebasing.

  So I checked out the remote branch rebased it resolved three conflicts and continued the rebase.

  Hope everything is as expected (:

ACKs for top commit:
  sipsorcery:
    ACK 1cabbddbca.
  practicalswift:
    ACK 1cabbddbca -- patch looks correct :)
  laanwj:
    ACK 1cabbddbca
  hebasto:
    ACK 1cabbddbca, I have reviewed the code and it looks OK, I agree it can be merged.

Tree-SHA512: 0e6bf64f274aae5dacb188358b4d5f65ccb207d4f70922f039bc4ed7934709418ddad19f8bfb7462517427837c3d2bb3f86ef284bb40e87119aad2a1e148d9d6
This commit is contained in:
Wladimir J. van der Laan 2020-07-09 16:33:26 +02:00
commit 0d69fdb9a0
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D
9 changed files with 28 additions and 22 deletions

View File

@ -8,6 +8,7 @@
#include <addrman.h> #include <addrman.h>
#include <chainparams.h> #include <chainparams.h>
#include <clientversion.h> #include <clientversion.h>
#include <cstdint>
#include <hash.h> #include <hash.h>
#include <random.h> #include <random.h>
#include <streams.h> #include <streams.h>
@ -36,7 +37,7 @@ template <typename Data>
bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data& data) bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data& data)
{ {
// Generate random temporary filename // Generate random temporary filename
unsigned short randv = 0; uint16_t randv = 0;
GetRandBytes((unsigned char*)&randv, sizeof(randv)); GetRandBytes((unsigned char*)&randv, sizeof(randv));
std::string tmpfn = strprintf("%s.%04x", prefix, randv); std::string tmpfn = strprintf("%s.%04x", prefix, randv);

View File

@ -42,6 +42,7 @@
static_assert(MINIUPNPC_API_VERSION >= 10, "miniUPnPc API version >= 10 assumed"); static_assert(MINIUPNPC_API_VERSION >= 10, "miniUPnPc API version >= 10 assumed");
#endif #endif
#include <cstdint>
#include <unordered_map> #include <unordered_map>
#include <math.h> #include <math.h>
@ -110,9 +111,9 @@ void CConnman::AddOneShot(const std::string& strDest)
vOneShots.push_back(strDest); vOneShots.push_back(strDest);
} }
unsigned short GetListenPort() uint16_t GetListenPort()
{ {
return (unsigned short)(gArgs.GetArg("-port", Params().GetDefaultPort())); return (uint16_t)(gArgs.GetArg("-port", Params().GetDefaultPort()));
} }
// find 'best' local address for a particular peer // find 'best' local address for a particular peer

View File

@ -25,8 +25,8 @@
#include <uint256.h> #include <uint256.h>
#include <atomic> #include <atomic>
#include <cstdint>
#include <deque> #include <deque>
#include <stdint.h>
#include <thread> #include <thread>
#include <memory> #include <memory>
#include <condition_variable> #include <condition_variable>
@ -482,7 +482,7 @@ void Discover();
void StartMapPort(); void StartMapPort();
void InterruptMapPort(); void InterruptMapPort();
void StopMapPort(); void StopMapPort();
unsigned short GetListenPort(); uint16_t GetListenPort();
struct CombinerAll struct CombinerAll
{ {

View File

@ -3,6 +3,7 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <cstdint>
#include <netaddress.h> #include <netaddress.h>
#include <hash.h> #include <hash.h>
#include <util/strencodings.h> #include <util/strencodings.h>
@ -627,15 +628,15 @@ CService::CService() : port(0)
{ {
} }
CService::CService(const CNetAddr& cip, unsigned short portIn) : CNetAddr(cip), port(portIn) CService::CService(const CNetAddr& cip, uint16_t portIn) : CNetAddr(cip), port(portIn)
{ {
} }
CService::CService(const struct in_addr& ipv4Addr, unsigned short portIn) : CNetAddr(ipv4Addr), port(portIn) CService::CService(const struct in_addr& ipv4Addr, uint16_t portIn) : CNetAddr(ipv4Addr), port(portIn)
{ {
} }
CService::CService(const struct in6_addr& ipv6Addr, unsigned short portIn) : CNetAddr(ipv6Addr), port(portIn) CService::CService(const struct in6_addr& ipv6Addr, uint16_t portIn) : CNetAddr(ipv6Addr), port(portIn)
{ {
} }
@ -663,7 +664,7 @@ bool CService::SetSockAddr(const struct sockaddr *paddr)
} }
} }
unsigned short CService::GetPort() const uint16_t CService::GetPort() const
{ {
return port; return port;
} }

View File

@ -12,7 +12,7 @@
#include <compat.h> #include <compat.h>
#include <serialize.h> #include <serialize.h>
#include <stdint.h> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
@ -143,10 +143,10 @@ class CService : public CNetAddr
public: public:
CService(); CService();
CService(const CNetAddr& ip, unsigned short port); CService(const CNetAddr& ip, uint16_t port);
CService(const struct in_addr& ipv4Addr, unsigned short port); CService(const struct in_addr& ipv4Addr, uint16_t port);
explicit CService(const struct sockaddr_in& addr); explicit CService(const struct sockaddr_in& addr);
unsigned short GetPort() const; uint16_t GetPort() const;
bool GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const; bool GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const;
bool SetSockAddr(const struct sockaddr* paddr); bool SetSockAddr(const struct sockaddr* paddr);
friend bool operator==(const CService& a, const CService& b); friend bool operator==(const CService& a, const CService& b);
@ -157,7 +157,7 @@ class CService : public CNetAddr
std::string ToStringPort() const; std::string ToStringPort() const;
std::string ToStringIPPort() const; std::string ToStringIPPort() const;
CService(const struct in6_addr& ipv6Addr, unsigned short port); CService(const struct in6_addr& ipv6Addr, uint16_t port);
explicit CService(const struct sockaddr_in6& addr); explicit CService(const struct sockaddr_in6& addr);
SERIALIZE_METHODS(CService, obj) { READWRITE(obj.ip, Using<BigEndianFormatter<2>>(obj.port)); } SERIALIZE_METHODS(CService, obj) { READWRITE(obj.ip, Using<BigEndianFormatter<2>>(obj.port)); }

View File

@ -12,6 +12,7 @@
#include <util/system.h> #include <util/system.h>
#include <atomic> #include <atomic>
#include <cstdint>
#ifndef WIN32 #ifndef WIN32
#include <fcntl.h> #include <fcntl.h>
@ -798,11 +799,11 @@ bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int
ProxyCredentials random_auth; ProxyCredentials random_auth;
static std::atomic_int counter(0); static std::atomic_int counter(0);
random_auth.username = random_auth.password = strprintf("%i", counter++); random_auth.username = random_auth.password = strprintf("%i", counter++);
if (!Socks5(strDest, (unsigned short)port, &random_auth, hSocket)) { if (!Socks5(strDest, (uint16_t)port, &random_auth, hSocket)) {
return false; return false;
} }
} else { } else {
if (!Socks5(strDest, (unsigned short)port, 0, hSocket)) { if (!Socks5(strDest, (uint16_t)port, 0, hSocket)) {
return false; return false;
} }
} }

View File

@ -6,6 +6,7 @@
#define BITCOIN_QT_OPTIONSMODEL_H #define BITCOIN_QT_OPTIONSMODEL_H
#include <amount.h> #include <amount.h>
#include <cstdint>
#include <qt/guiconstants.h> #include <qt/guiconstants.h>
#include <QAbstractListModel> #include <QAbstractListModel>
@ -15,7 +16,7 @@ class Node;
} }
extern const char *DEFAULT_GUI_PROXY_HOST; extern const char *DEFAULT_GUI_PROXY_HOST;
static constexpr unsigned short DEFAULT_GUI_PROXY_PORT = 9050; static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050;
/** /**
* Convert configured prune target MiB to displayed GB. Round up to avoid underestimating max disk usage. * Convert configured prune target MiB to displayed GB. Round up to avoid underestimating max disk usage.

View File

@ -9,13 +9,13 @@
#include <compat/endian.h> #include <compat/endian.h>
#include <algorithm> #include <algorithm>
#include <cstdint>
#include <cstring> #include <cstring>
#include <ios> #include <ios>
#include <limits> #include <limits>
#include <map> #include <map>
#include <memory> #include <memory>
#include <set> #include <set>
#include <stdint.h>
#include <string> #include <string>
#include <string.h> #include <string.h>
#include <utility> #include <utility>
@ -272,7 +272,7 @@ template<typename Stream> inline void Unserialize(Stream& s, bool& a) { char f=s
inline unsigned int GetSizeOfCompactSize(uint64_t nSize) inline unsigned int GetSizeOfCompactSize(uint64_t nSize)
{ {
if (nSize < 253) return sizeof(unsigned char); if (nSize < 253) return sizeof(unsigned char);
else if (nSize <= std::numeric_limits<unsigned short>::max()) return sizeof(unsigned char) + sizeof(unsigned short); else if (nSize <= std::numeric_limits<uint16_t>::max()) return sizeof(unsigned char) + sizeof(uint16_t);
else if (nSize <= std::numeric_limits<unsigned int>::max()) return sizeof(unsigned char) + sizeof(unsigned int); else if (nSize <= std::numeric_limits<unsigned int>::max()) return sizeof(unsigned char) + sizeof(unsigned int);
else return sizeof(unsigned char) + sizeof(uint64_t); else return sizeof(unsigned char) + sizeof(uint64_t);
} }
@ -286,7 +286,7 @@ void WriteCompactSize(Stream& os, uint64_t nSize)
{ {
ser_writedata8(os, nSize); ser_writedata8(os, nSize);
} }
else if (nSize <= std::numeric_limits<unsigned short>::max()) else if (nSize <= std::numeric_limits<uint16_t>::max())
{ {
ser_writedata8(os, 253); ser_writedata8(os, 253);
ser_writedata16(os, nSize); ser_writedata16(os, nSize);

View File

@ -6,6 +6,7 @@
#include <addrman.h> #include <addrman.h>
#include <chainparams.h> #include <chainparams.h>
#include <clientversion.h> #include <clientversion.h>
#include <cstdint>
#include <net.h> #include <net.h>
#include <netbase.h> #include <netbase.h>
#include <serialize.h> #include <serialize.h>
@ -83,10 +84,10 @@ BOOST_FIXTURE_TEST_SUITE(net_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(cnode_listen_port) BOOST_AUTO_TEST_CASE(cnode_listen_port)
{ {
// test default // test default
unsigned short port = GetListenPort(); uint16_t port = GetListenPort();
BOOST_CHECK(port == Params().GetDefaultPort()); BOOST_CHECK(port == Params().GetDefaultPort());
// test set port // test set port
unsigned short altPort = 12345; uint16_t altPort = 12345;
BOOST_CHECK(gArgs.SoftSetArg("-port", ToString(altPort))); BOOST_CHECK(gArgs.SoftSetArg("-port", ToString(altPort)));
port = GetListenPort(); port = GetListenPort();
BOOST_CHECK(port == altPort); BOOST_CHECK(port == altPort);