From: Andrei Pavel Date: Thu, 16 May 2024 12:45:41 +0000 (+0300) Subject: [#3256] attempt to fix nonsense Wstringop-overread X-Git-Tag: Kea-2.6.0~64 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=05362b115fdf6c082a1c21a85b53525dd824f417;p=thirdparty%2Fkea.git [#3256] attempt to fix nonsense Wstringop-overread ``` warning: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ reading 1 or more bytes from a region of size 0 [-Wstringop-overread] ``` and Wsign-compare in the same file: ``` test_control.cc:116:35: warning: comparison of integers of different signs: 'uint64_t' (aka 'unsigned long') and 'int' [-Wsign-compare] 338ms test_control.cc:491:43: warning: comparison of integers of different signs: 'size_type' (aka 'unsigned long') and 'const int' [-Wsign-compare] test_control.cc:529:50: warning: comparison of integers of different signs: 'size_type' (aka 'unsigned long') and 'const int' [-Wsign-compare] ``` --- diff --git a/src/bin/perfdhcp/test_control.cc b/src/bin/perfdhcp/test_control.cc index 4e0f22e1d2..6e37dbbfb9 100644 --- a/src/bin/perfdhcp/test_control.cc +++ b/src/bin/perfdhcp/test_control.cc @@ -113,7 +113,7 @@ TestControl::cleanCachedPackets() { // since we want to randomize leases to be renewed so leave 5 // times more packets to randomize from. /// @todo The cache size might be controlled from the command line. - if (reply_storage_.size() > 5 * options_.getRenewRate()) { + if (reply_storage_.size() > 5 * size_t(options_.getRenewRate())) { reply_storage_.clear(reply_storage_.size() - 5 * options_.getRenewRate()); } @@ -404,9 +404,11 @@ TestControl::generateMacAddress(uint8_t& randomized) { OptionPtr TestControl::generateClientId(const dhcp::HWAddrPtr& hwaddr) const { - std::vector client_id(1, static_cast(hwaddr->htype_)); - client_id.insert(client_id.end(), hwaddr->hwaddr_.begin(), - hwaddr->hwaddr_.end()); + vector client_id; + client_id.push_back(static_cast(hwaddr->htype_)); + for (uint8_t const& byte : hwaddr->hwaddr_) { + client_id.push_back(byte); + } return (OptionPtr(new Option(Option::V4, DHO_DHCP_CLIENT_IDENTIFIER, client_id))); } @@ -486,7 +488,7 @@ int TestControl::getRandomOffset(const int arg_idx) const { int rand_offset = options_.getIpVersion() == 4 ? DHCPV4_RANDOMIZATION_OFFSET : DHCPV6_RANDOMIZATION_OFFSET; - if (options_.getRandomOffset().size() > arg_idx) { + if (options_.getRandomOffset().size() > size_t(arg_idx)) { rand_offset = options_.getRandomOffset()[arg_idx]; } return (rand_offset); @@ -524,7 +526,7 @@ int TestControl::getTransactionIdOffset(const int arg_idx) const { int xid_offset = options_.getIpVersion() == 4 ? DHCPV4_TRANSID_OFFSET : DHCPV6_TRANSID_OFFSET; - if (options_.getTransactionIdOffset().size() > arg_idx) { + if (options_.getTransactionIdOffset().size() > size_t(arg_idx)) { xid_offset = options_.getTransactionIdOffset()[arg_idx]; } return (xid_offset);