now that warnings are enabled on test cases, clear a bunch of warnings

pull/630/head
Brad House 1 year ago
parent 33ee6c0573
commit 5262da7e88
  1. 17
      test/ares-test-init.cc
  2. 24
      test/ares-test-internal.cc
  3. 11
      test/ares-test-live.cc
  4. 2
      test/ares-test-misc.cc
  5. 3
      test/ares-test-mock-ai.cc
  6. 3
      test/ares-test-mock.cc
  7. 6
      test/ares-test-parse-caa.cc
  8. 10
      test/ares-test-parse-soa-any.cc
  9. 10
      test/ares-test-parse-soa.cc
  10. 16
      test/ares-test.cc
  11. 13
      test/ares-test.h
  12. 2
      test/dns-dump.cc
  13. 22
      test/dns-proto.cc

@ -74,8 +74,9 @@ TEST(LibraryInit, BasicChannelInit) {
}
TEST_F(LibraryTest, OptionsChannelInit) {
struct ares_options opts = {0};
struct ares_options opts;
int optmask = 0;
memset(&opts, 0, sizeof(opts));
opts.flags = ARES_FLAG_USEVC | ARES_FLAG_PRIMARY;
optmask |= ARES_OPT_FLAGS;
opts.timeout = 2000;
@ -97,12 +98,12 @@ TEST_F(LibraryTest, OptionsChannelInit) {
opts.ednspsz = 1280;
optmask |= ARES_OPT_EDNSPSZ;
opts.nservers = 2;
opts.servers = (struct in_addr *)malloc(opts.nservers * sizeof(struct in_addr));
opts.servers = (struct in_addr *)malloc((size_t)opts.nservers * sizeof(struct in_addr));
opts.servers[0].s_addr = htonl(0x01020304);
opts.servers[1].s_addr = htonl(0x02030405);
optmask |= ARES_OPT_SERVERS;
opts.ndomains = 2;
opts.domains = (char **)malloc(opts.ndomains * sizeof(char *));
opts.domains = (char **)malloc((size_t)opts.ndomains * sizeof(char *));
opts.domains[0] = strdup("example.com");
opts.domains[1] = strdup("example2.com");
optmask |= ARES_OPT_DOMAINS;
@ -122,8 +123,9 @@ TEST_F(LibraryTest, OptionsChannelInit) {
EXPECT_EQ(ARES_SUCCESS, ares_dup(&channel2, channel));
EXPECT_NE(nullptr, channel2);
struct ares_options opts2 = {0};
struct ares_options opts2;
int optmask2 = 0;
memset(&opts2, 0, sizeof(opts2));
EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel2, &opts2, &optmask2));
// Note that not all opts-settable fields are saved (e.g.
@ -167,8 +169,9 @@ TEST_F(LibraryTest, ChannelAllocFail) {
}
TEST_F(LibraryTest, OptionsChannelAllocFail) {
struct ares_options opts = {0};
struct ares_options opts;
int optmask = 0;
memset(&opts, 0, sizeof(opts));
opts.flags = ARES_FLAG_USEVC;
optmask |= ARES_OPT_FLAGS;
opts.timeout = 2;
@ -188,12 +191,12 @@ TEST_F(LibraryTest, OptionsChannelAllocFail) {
opts.ednspsz = 1280;
optmask |= ARES_OPT_EDNSPSZ;
opts.nservers = 2;
opts.servers = (struct in_addr *)malloc(opts.nservers * sizeof(struct in_addr));
opts.servers = (struct in_addr *)malloc((size_t)opts.nservers * sizeof(struct in_addr));
opts.servers[0].s_addr = htonl(0x01020304);
opts.servers[1].s_addr = htonl(0x02030405);
optmask |= ARES_OPT_SERVERS;
opts.ndomains = 2;
opts.domains = (char **)malloc(opts.ndomains * sizeof(char *));
opts.domains = (char **)malloc((size_t)opts.ndomains * sizeof(char *));
opts.domains[0] = strdup("example.com");
opts.domains[1] = strdup("example2.com");
optmask |= ARES_OPT_DOMAINS;

@ -283,7 +283,7 @@ TEST(Misc, Bitncmp) {
EXPECT_LT(0, ares__bitncmp(b, a, sizeof(a)*8));
EXPECT_EQ(0, ares__bitncmp(a, a, sizeof(a)*8));
for (int ii = 1; ii < (3*8+5); ii++) {
for (size_t ii = 1; ii < (3*8+5); ii++) {
EXPECT_EQ(0, ares__bitncmp(a, b, ii));
EXPECT_EQ(0, ares__bitncmp(b, a, ii));
EXPECT_LT(0, ares__bitncmp(a, c, ii));
@ -861,16 +861,16 @@ TEST_F(LibraryTest, BufMisuse) {
EXPECT_NE(ARES_SUCCESS, ares__buf_tag_rollback(NULL));
EXPECT_NE(ARES_SUCCESS, ares__buf_tag_clear(NULL));
EXPECT_EQ(NULL, ares__buf_tag_fetch(NULL, NULL));
EXPECT_EQ(0, ares__buf_tag_length(NULL));
EXPECT_EQ((size_t)0, ares__buf_tag_length(NULL));
EXPECT_NE(ARES_SUCCESS, ares__buf_tag_fetch_bytes(NULL, NULL, NULL));
EXPECT_NE(ARES_SUCCESS, ares__buf_tag_fetch_string(NULL, NULL, 0));
EXPECT_NE(ARES_SUCCESS, ares__buf_fetch_bytes_dup(NULL, 0, ARES_FALSE, NULL));
EXPECT_NE(ARES_SUCCESS, ares__buf_fetch_str_dup(NULL, 0, NULL));
EXPECT_EQ(0, ares__buf_consume_whitespace(NULL, ARES_FALSE));
EXPECT_EQ(0, ares__buf_consume_nonwhitespace(NULL));
EXPECT_EQ(0, ares__buf_consume_line(NULL, ARES_FALSE));
EXPECT_EQ((size_t)0, ares__buf_consume_whitespace(NULL, ARES_FALSE));
EXPECT_EQ((size_t)0, ares__buf_consume_nonwhitespace(NULL));
EXPECT_EQ((size_t)0, ares__buf_consume_line(NULL, ARES_FALSE));
EXPECT_NE(ARES_SUCCESS, ares__buf_begins_with(NULL, NULL, 0));
EXPECT_EQ(0, ares__buf_get_position(NULL));
EXPECT_EQ((size_t)0, ares__buf_get_position(NULL));
EXPECT_NE(ARES_SUCCESS, ares__buf_set_position(NULL, 0));
EXPECT_NE(ARES_SUCCESS, ares__dns_name_parse(NULL, NULL, ARES_FALSE));
EXPECT_NE(ARES_SUCCESS, ares__buf_parse_dns_binstr(NULL, 0, NULL, NULL, ARES_FALSE));
@ -881,28 +881,28 @@ TEST_F(LibraryTest, HtableMisuse) {
EXPECT_EQ(ARES_FALSE, ares__htable_insert(NULL, NULL));
EXPECT_EQ(NULL, ares__htable_get(NULL, NULL));
EXPECT_EQ(ARES_FALSE, ares__htable_remove(NULL, NULL));
EXPECT_EQ(0, ares__htable_num_keys(NULL));
EXPECT_EQ((size_t)0, ares__htable_num_keys(NULL));
}
TEST_F(LibraryTest, HtableAsvpMisuse) {
EXPECT_EQ(ARES_FALSE, ares__htable_asvp_insert(NULL, ARES_SOCKET_BAD, NULL));
EXPECT_EQ(ARES_FALSE, ares__htable_asvp_get(NULL, ARES_SOCKET_BAD, NULL));
EXPECT_EQ(ARES_FALSE, ares__htable_asvp_remove(NULL, ARES_SOCKET_BAD));
EXPECT_EQ(0, ares__htable_asvp_num_keys(NULL));
EXPECT_EQ((size_t)0, ares__htable_asvp_num_keys(NULL));
}
TEST_F(LibraryTest, HtableStrvpMisuse) {
EXPECT_EQ(ARES_FALSE, ares__htable_strvp_insert(NULL, NULL, NULL));
EXPECT_EQ(ARES_FALSE, ares__htable_strvp_get(NULL, NULL, NULL));
EXPECT_EQ(ARES_FALSE, ares__htable_strvp_remove(NULL, NULL));
EXPECT_EQ(0, ares__htable_strvp_num_keys(NULL));
EXPECT_EQ((size_t)0, ares__htable_strvp_num_keys(NULL));
}
TEST_F(LibraryTest, HtableSzvpMisuse) {
EXPECT_EQ(ARES_FALSE, ares__htable_szvp_insert(NULL, 0, NULL));
EXPECT_EQ(ARES_FALSE, ares__htable_szvp_get(NULL, 0, NULL));
EXPECT_EQ(ARES_FALSE, ares__htable_szvp_remove(NULL, 0));
EXPECT_EQ(0, ares__htable_szvp_num_keys(NULL));
EXPECT_EQ((size_t)0, ares__htable_szvp_num_keys(NULL));
}
TEST_F(LibraryTest, LlistMisuse) {
@ -912,7 +912,7 @@ TEST_F(LibraryTest, LlistMisuse) {
EXPECT_EQ(NULL, ares__llist_node_last(NULL));
EXPECT_EQ(NULL, ares__llist_node_next(NULL));
EXPECT_EQ(NULL, ares__llist_node_prev(NULL));
EXPECT_EQ(0, ares__llist_len(NULL));
EXPECT_EQ((size_t)0, ares__llist_len(NULL));
EXPECT_EQ(NULL, ares__llist_node_parent(NULL));
EXPECT_EQ(NULL, ares__llist_node_claim(NULL));
ares__llist_node_replace(NULL, NULL);
@ -928,7 +928,7 @@ TEST_F(LibraryTest, SlistMisuse) {
EXPECT_EQ(NULL, ares__slist_node_next(NULL));
EXPECT_EQ(NULL, ares__slist_node_prev(NULL));
EXPECT_EQ(NULL, ares__slist_node_val(NULL));
EXPECT_EQ(0, ares__slist_len(NULL));
EXPECT_EQ((size_t)0, ares__slist_len(NULL));
EXPECT_EQ(NULL, ares__slist_node_parent(NULL));
EXPECT_EQ(NULL, ares__slist_first_val(NULL));
EXPECT_EQ(NULL, ares__slist_last_val(NULL));

@ -679,7 +679,7 @@ VIRT_NONVIRT_TEST_F(DefaultChannelTest, GetSock) {
sock_cnt++;
}
}
EXPECT_NE(0, sock_cnt);
EXPECT_NE((size_t)0, sock_cnt);
bitmask = ares_getsock(channel_, nullptr, 0);
EXPECT_EQ(0, bitmask);
@ -689,7 +689,8 @@ VIRT_NONVIRT_TEST_F(DefaultChannelTest, GetSock) {
TEST_F(LibraryTest, GetTCPSock) {
ares_channel_t *channel;
struct ares_options opts = {0};
struct ares_options opts;
memset(&opts, 0, sizeof(opts));
opts.tcp_port = 53;
opts.flags = ARES_FLAG_USEVC;
int optmask = ARES_OPT_TCP_PORT | ARES_OPT_FLAGS;
@ -716,7 +717,7 @@ TEST_F(LibraryTest, GetTCPSock) {
sock_cnt++;
}
}
EXPECT_NE(0, sock_cnt);
EXPECT_NE((size_t)0, sock_cnt);
bitmask = ares_getsock(channel, nullptr, 0);
EXPECT_EQ(0, bitmask);
@ -747,7 +748,7 @@ TEST_F(DefaultChannelTest, VerifySocketFunctionCallback) {
Process();
EXPECT_TRUE(result.done_);
EXPECT_NE(0, count);
EXPECT_NE((size_t)0, count);
}
{
@ -762,7 +763,7 @@ TEST_F(DefaultChannelTest, VerifySocketFunctionCallback) {
EXPECT_TRUE(result.done_);
ares_destroy(copy);
EXPECT_NE(0, count);
EXPECT_NE((size_t)0, count);
}
}

@ -372,7 +372,7 @@ TEST_F(LibraryTest, ExpandName) {
long enclen;
std::vector<byte> data1 = {1, 'a', 2, 'b', 'c', 3, 'd', 'e', 'f', 0};
EXPECT_EQ("a.bc.def", ExpandName(data1, 0, &enclen));
EXPECT_EQ(data1.size(), enclen);
EXPECT_EQ(data1.size(), (size_t)enclen);
std::vector<byte> data2 = {0};
EXPECT_EQ("", ExpandName(data2, 0, &enclen));

@ -639,8 +639,9 @@ class NoRotateMultiMockTestAI : public MockMultiServerChannelTestAI {
};
TEST_P(NoRotateMultiMockTestAI, ThirdServer) {
struct ares_options opts = {0};
struct ares_options opts;
int optmask = 0;
memset(&opts, 0, sizeof(opts));
EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &opts, &optmask));
EXPECT_EQ(ARES_OPT_NOROTATE, (optmask & ARES_OPT_NOROTATE));
ares_destroy_options(&opts);

@ -1291,8 +1291,9 @@ class NoRotateMultiMockTest : public MockMultiServerChannelTest {
};
TEST_P(NoRotateMultiMockTest, ThirdServer) {
struct ares_options opts = {0};
struct ares_options opts;
int optmask = 0;
memset(&opts, 0, sizeof(opts));
EXPECT_EQ(ARES_SUCCESS, ares_save_options(channel_, &opts, &optmask));
EXPECT_EQ(ARES_OPT_NOROTATE, (optmask & ARES_OPT_NOROTATE));
ares_destroy_options(&opts);

@ -62,10 +62,10 @@ TEST_F(LibraryTest, ParseCaaReplySingleOK) {
EXPECT_EQ(ARES_SUCCESS, ares_parse_caa_reply(data.data(), (int)data.size(), &caa));
ASSERT_NE(nullptr, caa);
EXPECT_EQ(caa->critical, 0);
EXPECT_EQ(caa->plength, 5);
EXPECT_EQ(caa->critical, (int)0);
EXPECT_EQ(caa->plength, (size_t)5);
EXPECT_STREQ((char *)caa->property, "issue");
EXPECT_EQ(caa->length, 8);
EXPECT_EQ(caa->length, (size_t)8);
EXPECT_STREQ((char *)caa->value, "pki.goog");
ares_free_data(caa);

@ -41,11 +41,11 @@ TEST_F(LibraryTest, ParseSoaAnyReplyOK) {
ASSERT_NE(nullptr, soa);
EXPECT_EQ("soa1.example.com", std::string(soa->nsname));
EXPECT_EQ("fred.example.com", std::string(soa->hostmaster));
EXPECT_EQ(1, soa->serial);
EXPECT_EQ(2, soa->refresh);
EXPECT_EQ(3, soa->retry);
EXPECT_EQ(4, soa->expire);
EXPECT_EQ(5, soa->minttl);
EXPECT_EQ((unsigned int)1, soa->serial);
EXPECT_EQ((unsigned int)2, soa->refresh);
EXPECT_EQ((unsigned int)3, soa->retry);
EXPECT_EQ((unsigned int)4, soa->expire);
EXPECT_EQ((unsigned int)5, soa->minttl);
ares_free_data(soa);
}

@ -38,11 +38,11 @@ TEST_F(LibraryTest, ParseSoaReplyOK) {
ASSERT_NE(nullptr, soa);
EXPECT_EQ("soa1.example.com", std::string(soa->nsname));
EXPECT_EQ("fred.example.com", std::string(soa->hostmaster));
EXPECT_EQ(1, soa->serial);
EXPECT_EQ(2, soa->refresh);
EXPECT_EQ(3, soa->retry);
EXPECT_EQ(4, soa->expire);
EXPECT_EQ(5, soa->minttl);
EXPECT_EQ((unsigned int)1, soa->serial);
EXPECT_EQ((unsigned int)2, soa->refresh);
EXPECT_EQ((unsigned int)3, soa->retry);
EXPECT_EQ((unsigned int)4, soa->expire);
EXPECT_EQ((unsigned int)5, soa->minttl);
ares_free_data(soa);
}

16
test/ares-test.cc vendored

@ -288,7 +288,7 @@ MockServer::~MockServer() {
free(tcp_data_);
}
void MockServer::ProcessPacket(ares_socket_t fd, struct sockaddr_storage *addr, socklen_t addrlen,
void MockServer::ProcessPacket(ares_socket_t fd, struct sockaddr_storage *addr, ares_socklen_t addrlen,
byte *data, int len) {
// Assume the packet is a well-formed DNS request and extract the request
@ -381,14 +381,14 @@ void MockServer::ProcessFD(ares_socket_t fd) {
tcp_data_len_ = 0;
return;
}
tcp_data_ = (unsigned char *)realloc(tcp_data_, tcp_data_len_ + len);
memcpy(tcp_data_ + tcp_data_len_, buffer, len);
tcp_data_len_ += len;
tcp_data_ = (unsigned char *)realloc(tcp_data_, tcp_data_len_ + (size_t)len);
memcpy(tcp_data_ + tcp_data_len_, buffer, (size_t)len);
tcp_data_len_ += (size_t)len;
/* TCP might aggregate the various requests into a single packet, so we
* need to split */
while (tcp_data_len_ > 2) {
size_t tcplen = (tcp_data_[0] << 8) + tcp_data_[1];
size_t tcplen = ((size_t)tcp_data_[0] << 8) + (size_t)tcp_data_[1];
if (tcp_data_len_ - 2 < tcplen)
break;
@ -414,7 +414,7 @@ std::set<ares_socket_t> MockServer::fds() const {
return result;
}
void MockServer::ProcessRequest(ares_socket_t fd, struct sockaddr_storage* addr, int addrlen,
void MockServer::ProcessRequest(ares_socket_t fd, struct sockaddr_storage* addr, ares_socklen_t addrlen,
int qid, const std::string& name, int rrtype) {
// Before processing, let gMock know the request is happening.
OnRequest(name, rrtype);
@ -483,9 +483,9 @@ MockChannelOptsTest::MockChannelOptsTest(int count,
}
// Point the library at the first mock server by default (overridden below).
opts.udp_port = server_.udpport();
opts.udp_port = (unsigned short)server_.udpport();
optmask |= ARES_OPT_UDP_PORT;
opts.tcp_port = server_.tcpport();
opts.tcp_port = (unsigned short)server_.tcpport();
optmask |= ARES_OPT_TCP_PORT;
// If not already overridden, set short-ish timeouts.

13
test/ares-test.h vendored

@ -113,7 +113,8 @@ public:
DefaultChannelTest() : channel_(nullptr)
{
/* Enable query cache for live tests */
struct ares_options opts = { 0 };
struct ares_options opts;
memset(&opts, 0, sizeof(opts));
opts.qcache_max_ttl = 300;
int optmask = ARES_OPT_QUERY_CACHE;
EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel_, &opts, optmask));
@ -138,7 +139,8 @@ class FileChannelTest : public LibraryTest {
public:
FileChannelTest() : channel_(nullptr)
{
struct ares_options opts = { 0 };
struct ares_options opts;
memset(&opts, 0, sizeof(opts));
opts.lookups = strdup("f");
int optmask = ARES_OPT_LOOKUPS;
EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel_, &opts, optmask));
@ -166,7 +168,8 @@ class DefaultChannelModeTest
public:
DefaultChannelModeTest() : channel_(nullptr)
{
struct ares_options opts = { 0 };
struct ares_options opts;
memset(&opts, 0, sizeof(opts));
opts.lookups = strdup(GetParam().c_str());
int optmask = ARES_OPT_LOOKUPS;
EXPECT_EQ(ARES_SUCCESS, ares_init_options(&channel_, &opts, optmask));
@ -243,9 +246,9 @@ public:
}
private:
void ProcessRequest(ares_socket_t fd, struct sockaddr_storage *addr, int addrlen,
void ProcessRequest(ares_socket_t fd, struct sockaddr_storage *addr, ares_socklen_t addrlen,
int qid, const std::string &name, int rrtype);
void ProcessPacket(ares_socket_t fd, struct sockaddr_storage *addr, socklen_t addrlen,
void ProcessPacket(ares_socket_t fd, struct sockaddr_storage *addr, ares_socklen_t addrlen,
byte *data, int len);
int udpport_;
int tcpport_;

2
test/dns-dump.cc vendored

@ -39,7 +39,7 @@ static void ShowFile(const char* filename) {
std::vector<unsigned char> contents;
while (true) {
unsigned char buffer[1024];
int len = read(fd, buffer, sizeof(buffer));
ares_ssize_t len = read(fd, buffer, sizeof(buffer));
if (len <= 0) break;
contents.insert(contents.end(), buffer, buffer + len);
}

22
test/dns-proto.cc vendored

@ -479,15 +479,15 @@ std::string RRToString(const std::vector<byte>& packet,
}
void PushInt32(std::vector<byte>* data, int value) {
data->push_back((value & 0xff000000) >> 24);
data->push_back((value & 0x00ff0000) >> 16);
data->push_back((value & 0x0000ff00) >> 8);
data->push_back(value & 0x000000ff);
data->push_back((byte)((unsigned int)value & 0xff000000) >> 24);
data->push_back((byte)((unsigned int)value & 0x00ff0000) >> 16);
data->push_back((byte)((unsigned int)value & 0x0000ff00) >> 8);
data->push_back((byte)value & 0x000000ff);
}
void PushInt16(std::vector<byte>* data, int value) {
data->push_back((value & 0xff00) >> 8);
data->push_back(value & 0x00ff);
data->push_back((byte)(value & 0xff00) >> 8);
data->push_back((byte)value & 0x00ff);
}
std::vector<byte> EncodeString(const std::string& name) {
@ -500,7 +500,7 @@ std::vector<byte> EncodeString(const std::string& name) {
* terminator, so don't do it twice */
if (label.length() == 0)
break;
data.push_back(label.length());
data.push_back((byte)label.length());
data.insert(data.end(), label.begin(), label.end());
}
data.push_back(0);
@ -539,7 +539,7 @@ std::vector<byte> DNSTxtRR::data() const {
}
PushInt16(&data, len);
for (const std::string& txt : txt_) {
data.push_back(txt.size());
data.push_back((byte)txt.size());
data.insert(data.end(), txt.begin(), txt.end());
}
return data;
@ -623,11 +623,11 @@ std::vector<byte> DNSNaptrRR::data() const {
PushInt16(&data, len);
PushInt16(&data, order_);
PushInt16(&data, pref_);
data.push_back(flags_.size());
data.push_back((byte)flags_.size());
data.insert(data.end(), flags_.begin(), flags_.end());
data.push_back(service_.size());
data.push_back((byte)service_.size());
data.insert(data.end(), service_.begin(), service_.end());
data.push_back(regexp_.size());
data.push_back((byte)regexp_.size());
data.insert(data.end(), regexp_.begin(), regexp_.end());
data.insert(data.end(), encname.begin(), encname.end());
return data;

Loading…
Cancel
Save