Skip to content

Commit

Permalink
tests: Avoid using C-style NUL-terminated strings as arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift authored and furszy committed Aug 10, 2021
1 parent f6c52a3 commit 9f9c871
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
13 changes: 2 additions & 11 deletions src/test/addrman_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,29 +93,20 @@ class CAddrManTest : public CAddrMan

};

static CNetAddr ResolveIP(const char* ip)
static CNetAddr ResolveIP(const std::string& ip)
{
CNetAddr addr;
BOOST_CHECK_MESSAGE(LookupHost(ip, addr, false), strprintf("failed to resolve: %s", ip));
return addr;
}

static CNetAddr ResolveIP(std::string ip)
{
return ResolveIP(ip.c_str());
}

static CService ResolveService(const char* ip, int port = 0)
static CService ResolveService(const std::string& ip, const int port = 0)
{
CService serv;
BOOST_CHECK_MESSAGE(Lookup(ip, serv, port, false), strprintf("failed to resolve: %s:%i", ip, port));
return serv;
}

static CService ResolveService(std::string ip, int port = 0)
{
return ResolveService(ip.c_str(), port);
}

static std::vector<bool> FromBytes(const unsigned char* source, int vector_size) {
std::vector<bool> result(vector_size);
Expand Down
6 changes: 3 additions & 3 deletions src/test/netbase_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@

BOOST_FIXTURE_TEST_SUITE(netbase_tests, BasicTestingSetup)

static CNetAddr ResolveIP(const char* ip)
static CNetAddr ResolveIP(const std::string& ip)
{
CNetAddr addr;
LookupHost(ip, addr, false);
return addr;
}

static CSubNet ResolveSubNet(const char* subnet)
static CSubNet ResolveSubNet(const std::string& subnet)
{
CSubNet ret;
LookupSubNet(subnet, ret);
return ret;
}

static CNetAddr CreateInternal(const char* host)
static CNetAddr CreateInternal(const std::string& host)
{
CNetAddr addr;
addr.SetInternal(host);
Expand Down

0 comments on commit 9f9c871

Please sign in to comment.