Skip to content

Commit 0d69fdb

Browse files
committed
Merge #19314: refactor: Use uint16_t instead of unsigned short
1cabbdd 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 1cabbdd. practicalswift: ACK 1cabbdd -- patch looks correct :) laanwj: ACK 1cabbdd hebasto: ACK 1cabbdd, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 0e6bf64f274aae5dacb188358b4d5f65ccb207d4f70922f039bc4ed7934709418ddad19f8bfb7462517427837c3d2bb3f86ef284bb40e87119aad2a1e148d9d6
2 parents 22ccc27 + 1cabbdd commit 0d69fdb

File tree

9 files changed

+28
-22
lines changed

9 files changed

+28
-22
lines changed

src/addrdb.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <addrman.h>
99
#include <chainparams.h>
1010
#include <clientversion.h>
11+
#include <cstdint>
1112
#include <hash.h>
1213
#include <random.h>
1314
#include <streams.h>
@@ -36,7 +37,7 @@ template <typename Data>
3637
bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data& data)
3738
{
3839
// Generate random temporary filename
39-
unsigned short randv = 0;
40+
uint16_t randv = 0;
4041
GetRandBytes((unsigned char*)&randv, sizeof(randv));
4142
std::string tmpfn = strprintf("%s.%04x", prefix, randv);
4243

src/net.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
static_assert(MINIUPNPC_API_VERSION >= 10, "miniUPnPc API version >= 10 assumed");
4343
#endif
4444

45+
#include <cstdint>
4546
#include <unordered_map>
4647

4748
#include <math.h>
@@ -110,9 +111,9 @@ void CConnman::AddOneShot(const std::string& strDest)
110111
vOneShots.push_back(strDest);
111112
}
112113

113-
unsigned short GetListenPort()
114+
uint16_t GetListenPort()
114115
{
115-
return (unsigned short)(gArgs.GetArg("-port", Params().GetDefaultPort()));
116+
return (uint16_t)(gArgs.GetArg("-port", Params().GetDefaultPort()));
116117
}
117118

118119
// find 'best' local address for a particular peer

src/net.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
#include <uint256.h>
2626

2727
#include <atomic>
28+
#include <cstdint>
2829
#include <deque>
29-
#include <stdint.h>
3030
#include <thread>
3131
#include <memory>
3232
#include <condition_variable>
@@ -482,7 +482,7 @@ void Discover();
482482
void StartMapPort();
483483
void InterruptMapPort();
484484
void StopMapPort();
485-
unsigned short GetListenPort();
485+
uint16_t GetListenPort();
486486

487487
struct CombinerAll
488488
{

src/netaddress.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Distributed under the MIT software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

6+
#include <cstdint>
67
#include <netaddress.h>
78
#include <hash.h>
89
#include <util/strencodings.h>
@@ -627,15 +628,15 @@ CService::CService() : port(0)
627628
{
628629
}
629630

630-
CService::CService(const CNetAddr& cip, unsigned short portIn) : CNetAddr(cip), port(portIn)
631+
CService::CService(const CNetAddr& cip, uint16_t portIn) : CNetAddr(cip), port(portIn)
631632
{
632633
}
633634

634-
CService::CService(const struct in_addr& ipv4Addr, unsigned short portIn) : CNetAddr(ipv4Addr), port(portIn)
635+
CService::CService(const struct in_addr& ipv4Addr, uint16_t portIn) : CNetAddr(ipv4Addr), port(portIn)
635636
{
636637
}
637638

638-
CService::CService(const struct in6_addr& ipv6Addr, unsigned short portIn) : CNetAddr(ipv6Addr), port(portIn)
639+
CService::CService(const struct in6_addr& ipv6Addr, uint16_t portIn) : CNetAddr(ipv6Addr), port(portIn)
639640
{
640641
}
641642

@@ -663,7 +664,7 @@ bool CService::SetSockAddr(const struct sockaddr *paddr)
663664
}
664665
}
665666

666-
unsigned short CService::GetPort() const
667+
uint16_t CService::GetPort() const
667668
{
668669
return port;
669670
}

src/netaddress.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <compat.h>
1313
#include <serialize.h>
1414

15-
#include <stdint.h>
15+
#include <cstdint>
1616
#include <string>
1717
#include <vector>
1818

@@ -143,10 +143,10 @@ class CService : public CNetAddr
143143

144144
public:
145145
CService();
146-
CService(const CNetAddr& ip, unsigned short port);
147-
CService(const struct in_addr& ipv4Addr, unsigned short port);
146+
CService(const CNetAddr& ip, uint16_t port);
147+
CService(const struct in_addr& ipv4Addr, uint16_t port);
148148
explicit CService(const struct sockaddr_in& addr);
149-
unsigned short GetPort() const;
149+
uint16_t GetPort() const;
150150
bool GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const;
151151
bool SetSockAddr(const struct sockaddr* paddr);
152152
friend bool operator==(const CService& a, const CService& b);
@@ -157,7 +157,7 @@ class CService : public CNetAddr
157157
std::string ToStringPort() const;
158158
std::string ToStringIPPort() const;
159159

160-
CService(const struct in6_addr& ipv6Addr, unsigned short port);
160+
CService(const struct in6_addr& ipv6Addr, uint16_t port);
161161
explicit CService(const struct sockaddr_in6& addr);
162162

163163
SERIALIZE_METHODS(CService, obj) { READWRITE(obj.ip, Using<BigEndianFormatter<2>>(obj.port)); }

src/netbase.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <util/system.h>
1313

1414
#include <atomic>
15+
#include <cstdint>
1516

1617
#ifndef WIN32
1718
#include <fcntl.h>
@@ -798,11 +799,11 @@ bool ConnectThroughProxy(const proxyType &proxy, const std::string& strDest, int
798799
ProxyCredentials random_auth;
799800
static std::atomic_int counter(0);
800801
random_auth.username = random_auth.password = strprintf("%i", counter++);
801-
if (!Socks5(strDest, (unsigned short)port, &random_auth, hSocket)) {
802+
if (!Socks5(strDest, (uint16_t)port, &random_auth, hSocket)) {
802803
return false;
803804
}
804805
} else {
805-
if (!Socks5(strDest, (unsigned short)port, 0, hSocket)) {
806+
if (!Socks5(strDest, (uint16_t)port, 0, hSocket)) {
806807
return false;
807808
}
808809
}

src/qt/optionsmodel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_QT_OPTIONSMODEL_H
77

88
#include <amount.h>
9+
#include <cstdint>
910
#include <qt/guiconstants.h>
1011

1112
#include <QAbstractListModel>
@@ -15,7 +16,7 @@ class Node;
1516
}
1617

1718
extern const char *DEFAULT_GUI_PROXY_HOST;
18-
static constexpr unsigned short DEFAULT_GUI_PROXY_PORT = 9050;
19+
static constexpr uint16_t DEFAULT_GUI_PROXY_PORT = 9050;
1920

2021
/**
2122
* Convert configured prune target MiB to displayed GB. Round up to avoid underestimating max disk usage.

src/serialize.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#include <compat/endian.h>
1010

1111
#include <algorithm>
12+
#include <cstdint>
1213
#include <cstring>
1314
#include <ios>
1415
#include <limits>
1516
#include <map>
1617
#include <memory>
1718
#include <set>
18-
#include <stdint.h>
1919
#include <string>
2020
#include <string.h>
2121
#include <utility>
@@ -272,7 +272,7 @@ template<typename Stream> inline void Unserialize(Stream& s, bool& a) { char f=s
272272
inline unsigned int GetSizeOfCompactSize(uint64_t nSize)
273273
{
274274
if (nSize < 253) return sizeof(unsigned char);
275-
else if (nSize <= std::numeric_limits<unsigned short>::max()) return sizeof(unsigned char) + sizeof(unsigned short);
275+
else if (nSize <= std::numeric_limits<uint16_t>::max()) return sizeof(unsigned char) + sizeof(uint16_t);
276276
else if (nSize <= std::numeric_limits<unsigned int>::max()) return sizeof(unsigned char) + sizeof(unsigned int);
277277
else return sizeof(unsigned char) + sizeof(uint64_t);
278278
}
@@ -286,7 +286,7 @@ void WriteCompactSize(Stream& os, uint64_t nSize)
286286
{
287287
ser_writedata8(os, nSize);
288288
}
289-
else if (nSize <= std::numeric_limits<unsigned short>::max())
289+
else if (nSize <= std::numeric_limits<uint16_t>::max())
290290
{
291291
ser_writedata8(os, 253);
292292
ser_writedata16(os, nSize);

src/test/net_tests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <addrman.h>
77
#include <chainparams.h>
88
#include <clientversion.h>
9+
#include <cstdint>
910
#include <net.h>
1011
#include <netbase.h>
1112
#include <serialize.h>
@@ -83,10 +84,10 @@ BOOST_FIXTURE_TEST_SUITE(net_tests, BasicTestingSetup)
8384
BOOST_AUTO_TEST_CASE(cnode_listen_port)
8485
{
8586
// test default
86-
unsigned short port = GetListenPort();
87+
uint16_t port = GetListenPort();
8788
BOOST_CHECK(port == Params().GetDefaultPort());
8889
// test set port
89-
unsigned short altPort = 12345;
90+
uint16_t altPort = 12345;
9091
BOOST_CHECK(gArgs.SoftSetArg("-port", ToString(altPort)));
9192
port = GetListenPort();
9293
BOOST_CHECK(port == altPort);

0 commit comments

Comments
 (0)