Skip to content

Commit 7a046cd

Browse files
tests: Avoid using C-style NUL-terminated strings as arguments
1 parent fefb916 commit 7a046cd

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

src/test/addrman_tests.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,20 @@ class CAddrManTest : public CAddrMan
5959
}
6060
};
6161

62-
static CNetAddr ResolveIP(const char* ip)
62+
static CNetAddr ResolveIP(const std::string& ip)
6363
{
6464
CNetAddr addr;
6565
BOOST_CHECK_MESSAGE(LookupHost(ip, addr, false), strprintf("failed to resolve: %s", ip));
6666
return addr;
6767
}
6868

69-
static CNetAddr ResolveIP(std::string ip)
70-
{
71-
return ResolveIP(ip.c_str());
72-
}
73-
74-
static CService ResolveService(const char* ip, int port = 0)
69+
static CService ResolveService(const std::string& ip, const int port = 0)
7570
{
7671
CService serv;
7772
BOOST_CHECK_MESSAGE(Lookup(ip, serv, port, false), strprintf("failed to resolve: %s:%i", ip, port));
7873
return serv;
7974
}
8075

81-
static CService ResolveService(std::string ip, int port = 0)
82-
{
83-
return ResolveService(ip.c_str(), port);
84-
}
8576

8677
BOOST_FIXTURE_TEST_SUITE(addrman_tests, BasicTestingSetup)
8778

src/test/netbase_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@
1313

1414
BOOST_FIXTURE_TEST_SUITE(netbase_tests, BasicTestingSetup)
1515

16-
static CNetAddr ResolveIP(const char* ip)
16+
static CNetAddr ResolveIP(const std::string& ip)
1717
{
1818
CNetAddr addr;
1919
LookupHost(ip, addr, false);
2020
return addr;
2121
}
2222

23-
static CSubNet ResolveSubNet(const char* subnet)
23+
static CSubNet ResolveSubNet(const std::string& subnet)
2424
{
2525
CSubNet ret;
2626
LookupSubNet(subnet, ret);
2727
return ret;
2828
}
2929

30-
static CNetAddr CreateInternal(const char* host)
30+
static CNetAddr CreateInternal(const std::string& host)
3131
{
3232
CNetAddr addr;
3333
addr.SetInternal(host);

0 commit comments

Comments
 (0)