From 6fbf286f98365bcc85f85c90e8de7beabcd8fd28 Mon Sep 17 00:00:00 2001 From: Francis Dupont Date: Tue, 11 Mar 2025 16:44:24 +0100 Subject: [PATCH] [#3785] Checkpoint --- src/hooks/dhcp/mysql/mysql_cb_dhcp4.cc | 4 +-- src/hooks/dhcp/mysql/mysql_cb_dhcp6.cc | 4 +-- src/hooks/dhcp/mysql/mysql_cb_impl.cc | 2 +- src/hooks/dhcp/pgsql/pgsql_cb_impl.cc | 4 +-- src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc | 2 +- src/lib/asiolink/addr_utilities.cc | 4 +-- .../testutils/test_server_unix_socket.cc | 2 +- src/lib/dhcp/classify.cc | 2 +- src/lib/dhcp/iface_mgr.cc | 2 +- src/lib/dhcp/opaque_data_tuple.cc | 4 +-- src/lib/dhcp/option6_ia.cc | 2 +- src/lib/dhcp/option6_iaaddr.cc | 2 +- src/lib/dhcp/option6_iaprefix.cc | 2 +- src/lib/dhcp/option6_status_code.cc | 4 +-- src/lib/dhcp/option_classless_static_route.cc | 3 +- src/lib/dhcp/option_custom.cc | 11 ++++---- src/lib/dhcp/option_definition.cc | 6 ++-- src/lib/dhcp/option_int.h | 2 +- src/lib/dhcp/option_opaque_data_tuples.cc | 2 +- src/lib/dhcp/option_vendor_class.cc | 2 +- src/lib/dhcpsrv/cfg_expiration.cc | 2 +- src/lib/dhcpsrv/flq_allocator.cc | 4 +-- src/lib/dhcpsrv/lease_mgr.cc | 6 ++-- src/lib/dhcpsrv/memfile_lease_limits.cc | 2 +- src/lib/dhcpsrv/memfile_lease_mgr.cc | 24 +++++++++------- src/lib/dhcpsrv/packet_fuzzer.cc | 2 +- src/lib/dhcpsrv/random_allocator.cc | 4 +-- src/lib/dns/labelsequence.cc | 3 +- src/lib/dns/message.cc | 28 ++++++++++--------- src/lib/eval/token.cc | 4 +-- src/lib/hooks/callout_manager.cc | 7 +++-- src/lib/hooks/library_handle.cc | 2 +- src/lib/pgsql/pgsql_connection.cc | 2 +- src/lib/pgsql/pgsql_exchange.cc | 2 +- src/lib/testutils/log_utils.cc | 2 +- src/lib/testutils/unix_control_client.cc | 2 +- src/lib/yang/adaptor.cc | 6 ++-- 37 files changed, 89 insertions(+), 79 deletions(-) diff --git a/src/hooks/dhcp/mysql/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql/mysql_cb_dhcp4.cc index 23cf59210a..2a4d81f00f 100644 --- a/src/hooks/dhcp/mysql/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql/mysql_cb_dhcp4.cc @@ -490,7 +490,7 @@ public: isc_throw(BadValue, "invalid relay value " << out_bindings[12]->getString()); } - for (auto i = 0; i < relay_element->size(); ++i) { + for (unsigned i = 0; i < relay_element->size(); ++i) { auto relay_address_element = relay_element->get(i); if (relay_address_element->getType() != Element::string) { isc_throw(BadValue, "relay address must be a string"); @@ -1414,7 +1414,7 @@ public: isc_throw(BadValue, "invalid relay value " << out_bindings[7]->getString()); } - for (auto i = 0; i < relay_element->size(); ++i) { + for (unsigned i = 0; i < relay_element->size(); ++i) { auto relay_address_element = relay_element->get(i); if (relay_address_element->getType() != Element::string) { isc_throw(BadValue, "relay address must be a string"); diff --git a/src/hooks/dhcp/mysql/mysql_cb_dhcp6.cc b/src/hooks/dhcp/mysql/mysql_cb_dhcp6.cc index 410586f7c8..ab96f4faf4 100644 --- a/src/hooks/dhcp/mysql/mysql_cb_dhcp6.cc +++ b/src/hooks/dhcp/mysql/mysql_cb_dhcp6.cc @@ -503,7 +503,7 @@ public: isc_throw(BadValue, "invalid relay value " << out_bindings[8]->getString()); } - for (auto i = 0; i < relay_element->size(); ++i) { + for (unsigned i = 0; i < relay_element->size(); ++i) { auto relay_address_element = relay_element->get(i); if (relay_address_element->getType() != Element::string) { isc_throw(BadValue, "relay address must be a string"); @@ -1725,7 +1725,7 @@ public: isc_throw(BadValue, "invalid relay value " << out_bindings[8]->getString()); } - for (auto i = 0; i < relay_element->size(); ++i) { + for (unsigned i = 0; i < relay_element->size(); ++i) { auto relay_address_element = relay_element->get(i); if (relay_address_element->getType() != Element::string) { isc_throw(BadValue, "relay address must be a string"); diff --git a/src/hooks/dhcp/mysql/mysql_cb_impl.cc b/src/hooks/dhcp/mysql/mysql_cb_impl.cc index e61663176f..e0f30e3f6d 100644 --- a/src/hooks/dhcp/mysql/mysql_cb_impl.cc +++ b/src/hooks/dhcp/mysql/mysql_cb_impl.cc @@ -927,7 +927,7 @@ MySqlConfigBackendImpl::processOptionDefRow(MySqlBindingCollection::iterator fir // This element must contain a list of integers specifying // types of the record fields. - for (auto i = 0; i < record_types_element->size(); ++i) { + for (unsigned i = 0; i < record_types_element->size(); ++i) { auto type_element = record_types_element->get(i); if (type_element->getType() != Element::integer) { isc_throw(BadValue, "record type values must be integers"); diff --git a/src/hooks/dhcp/pgsql/pgsql_cb_impl.cc b/src/hooks/dhcp/pgsql/pgsql_cb_impl.cc index e324281825..26e9fdc4de 100644 --- a/src/hooks/dhcp/pgsql/pgsql_cb_impl.cc +++ b/src/hooks/dhcp/pgsql/pgsql_cb_impl.cc @@ -904,7 +904,7 @@ PgSqlConfigBackendImpl::processOptionDefRow(PgSqlResultRowWorker& worker, // This element must contain a list of integers specifying // types of the record fields. - for (auto i = 0; i < record_types_element->size(); ++i) { + for (unsigned i = 0; i < record_types_element->size(); ++i) { auto type_element = record_types_element->get(i); if (type_element->getType() != Element::integer) { isc_throw(BadValue, "record type values must be integers"); @@ -1127,7 +1127,7 @@ PgSqlConfigBackendImpl::setRelays(PgSqlResultRowWorker& worker, size_t col, Netw isc_throw(BadValue, "invalid relay list: " << worker.getString(col)); } - for (auto i = 0; i < relay_element->size(); ++i) { + for (unsigned i = 0; i < relay_element->size(); ++i) { auto relay_address_element = relay_element->get(i); if (relay_address_element->getType() != Element::string) { isc_throw(BadValue, "elements of relay_addresses list must" diff --git a/src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc b/src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc index 39a11a73fd..fe57525607 100644 --- a/src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc +++ b/src/hooks/dhcp/pgsql/pgsql_lease_mgr.cc @@ -1446,7 +1446,7 @@ public: /// rows to fetch. bool getNextRow(LeaseStatsRow& row) { // If we're past the end, punt. - if (next_row_ >= result_set_->getRows()) { + if (static_cast(next_row_) >= result_set_->getRows()) { return (false); } diff --git a/src/lib/asiolink/addr_utilities.cc b/src/lib/asiolink/addr_utilities.cc index 5b03349aa1..47e8d6f6f3 100644 --- a/src/lib/asiolink/addr_utilities.cc +++ b/src/lib/asiolink/addr_utilities.cc @@ -76,7 +76,7 @@ IOAddress firstAddrInPrefix6(const IOAddress& prefix, uint8_t len) { } // Clear out the remaining bits. - for (int i = len / 8; i < sizeof(packed); ++i) { + for (unsigned i = len / 8; i < sizeof(packed); ++i) { packed[i] = 0x0; } @@ -156,7 +156,7 @@ IOAddress lastAddrInPrefix6(const IOAddress& prefix, uint8_t len) { } // Finally set remaining bits to 1. - for (int i = len / 8; i < sizeof(packed); ++i) { + for (unsigned i = len / 8; i < sizeof(packed); ++i) { packed[i] = 0xff; } diff --git a/src/lib/asiolink/testutils/test_server_unix_socket.cc b/src/lib/asiolink/testutils/test_server_unix_socket.cc index 7fccc49991..33f3048f86 100644 --- a/src/lib/asiolink/testutils/test_server_unix_socket.cc +++ b/src/lib/asiolink/testutils/test_server_unix_socket.cc @@ -244,7 +244,7 @@ void TestServerUnixSocket::generateCustomResponse(const uint64_t response_size) { std::ostringstream s; s << "{"; - while (s.tellp() < response_size) { + while (s.tellp() < static_cast(response_size)) { s << "\"param\": \"value\","; } s << "}"; diff --git a/src/lib/dhcp/classify.cc b/src/lib/dhcp/classify.cc index 38943342be..d8b00dfd4f 100644 --- a/src/lib/dhcp/classify.cc +++ b/src/lib/dhcp/classify.cc @@ -108,7 +108,7 @@ ClientClasses::fromElement(isc::data::ConstElementPtr cc_list) { isc_throw(BadValue, "not a List element"); } - for (auto i = 0; i < cc_list->size(); ++i) { + for (unsigned i = 0; i < cc_list->size(); ++i) { auto cclass = cc_list->get(i); if (cclass->getType() != Element::string) { isc_throw(BadValue, "elements of list must be valid strings"); diff --git a/src/lib/dhcp/iface_mgr.cc b/src/lib/dhcp/iface_mgr.cc index 758205b37c..960e71db3e 100644 --- a/src/lib/dhcp/iface_mgr.cc +++ b/src/lib/dhcp/iface_mgr.cc @@ -132,7 +132,7 @@ Iface::getPlainMac() const { ostringstream tmp; tmp.fill('0'); tmp << hex; - for (int i = 0; i < mac_len_; i++) { + for (unsigned i = 0; i < mac_len_; i++) { tmp.width(2); tmp << static_cast(mac_[i]); if (i < mac_len_-1) { diff --git a/src/lib/dhcp/opaque_data_tuple.cc b/src/lib/dhcp/opaque_data_tuple.cc index 343ed6ef2a..4d5340f091 100644 --- a/src/lib/dhcp/opaque_data_tuple.cc +++ b/src/lib/dhcp/opaque_data_tuple.cc @@ -52,7 +52,7 @@ OpaqueDataTuple::getText() const { void OpaqueDataTuple::pack(isc::util::OutputBuffer& buf) const { - if ((1 << (getDataFieldSize() * 8)) <= getLength()) { + if ((1U << (getDataFieldSize() * 8)) <= getLength()) { isc_throw(OpaqueDataTupleError, "failed to create on-wire format of the" " opaque data field, because current data length " << getLength() << " exceeds the maximum size for the length" @@ -130,7 +130,7 @@ OpaqueDataTuple::unpack(OpaqueDataTuple::InputIterator begin, OpaqueDataTuple::I // reminder of the buffer is long enough. begin += getDataFieldSize(); // Attempt to parse as a length-value pair. - if (std::distance(begin, end) < len) { + if (static_cast(std::distance(begin, end)) < len) { if (Option::lenient_parsing_) { // Fallback to parsing the rest of the option as a single value. len = std::distance(begin, end); diff --git a/src/lib/dhcp/option6_ia.cc b/src/lib/dhcp/option6_ia.cc index 72aaf743ad..0e1e7689cf 100644 --- a/src/lib/dhcp/option6_ia.cc +++ b/src/lib/dhcp/option6_ia.cc @@ -68,7 +68,7 @@ void Option6IA::unpack(OptionBufferConstIter begin, OptionBufferConstIter end) { // IA_NA and IA_PD have 12 bytes content (iaid, t1, t2 fields) // followed by 0 or more sub-options. - if (distance(begin, end) < OPTION6_IA_LEN) { + if (static_cast(distance(begin, end)) < OPTION6_IA_LEN) { isc_throw(OutOfRange, "Option " << type_ << " truncated"); } iaid_ = readUint32(&(*begin), distance(begin, end)); diff --git a/src/lib/dhcp/option6_iaaddr.cc b/src/lib/dhcp/option6_iaaddr.cc index 9836ad909c..86e1821c36 100644 --- a/src/lib/dhcp/option6_iaaddr.cc +++ b/src/lib/dhcp/option6_iaaddr.cc @@ -70,7 +70,7 @@ void Option6IAAddr::pack(isc::util::OutputBuffer& buf, bool) const { void Option6IAAddr::unpack(OptionBuffer::const_iterator begin, OptionBuffer::const_iterator end) { - if ( distance(begin, end) < OPTION6_IAADDR_LEN) { + if (static_cast(distance(begin, end)) < OPTION6_IAADDR_LEN) { isc_throw(OutOfRange, "Option " << type_ << " truncated"); } diff --git a/src/lib/dhcp/option6_iaprefix.cc b/src/lib/dhcp/option6_iaprefix.cc index ceb40f9b5a..bc80f86ff3 100644 --- a/src/lib/dhcp/option6_iaprefix.cc +++ b/src/lib/dhcp/option6_iaprefix.cc @@ -73,7 +73,7 @@ void Option6IAPrefix::pack(isc::util::OutputBuffer& buf, bool) const { void Option6IAPrefix::unpack(OptionBuffer::const_iterator begin, OptionBuffer::const_iterator end) { - if ( distance(begin, end) < OPTION6_IAPREFIX_LEN) { + if (static_cast(distance(begin, end)) < OPTION6_IAPREFIX_LEN) { isc_throw(OutOfRange, "Option " << type_ << " truncated"); } diff --git a/src/lib/dhcp/option6_status_code.cc b/src/lib/dhcp/option6_status_code.cc index 46a06ebf69..7162c3c640 100644 --- a/src/lib/dhcp/option6_status_code.cc +++ b/src/lib/dhcp/option6_status_code.cc @@ -64,7 +64,7 @@ Option6StatusCode::pack(isc::util::OutputBuffer& buf, bool) const { void Option6StatusCode::unpack(OptionBufferConstIter begin, OptionBufferConstIter end) { // Make sure that the option is not truncated. - if (std::distance(begin, end) < OPTION6_STATUS_CODE_MIN_LEN) { + if (static_cast(std::distance(begin, end)) < OPTION6_STATUS_CODE_MIN_LEN) { isc_throw(OutOfRange, "Status Code option (" << D6O_STATUS_CODE << ") truncated"); } @@ -174,7 +174,7 @@ Option4SlpServiceScope::pack(isc::util::OutputBuffer& buf, bool check) const { void Option4SlpServiceScope::unpack(OptionBufferConstIter begin, OptionBufferConstIter end) { // Make sure that the option is not truncated. - if (std::distance(begin, end) < OPTION4_SLP_SERVICE_SCOPEMIN_LEN) { + if (static_cast(std::distance(begin, end)) < OPTION4_SLP_SERVICE_SCOPEMIN_LEN) { isc_throw(OutOfRange, "SLP Service Scope option (" << DHO_SERVICE_SCOPE << ") truncated"); } diff --git a/src/lib/dhcp/option_classless_static_route.cc b/src/lib/dhcp/option_classless_static_route.cc index d6cc494065..5ddf42d465 100644 --- a/src/lib/dhcp/option_classless_static_route.cc +++ b/src/lib/dhcp/option_classless_static_route.cc @@ -152,7 +152,8 @@ OptionClasslessStaticRoute::parseWireData(OptionBufferConstIter begin, OptionBuf ++begin; // once we know haw many significant octets there are, check for truncated data again - if (distance(begin, end) < (significant_octets + V4ADDRESS_LEN)) { + if (static_cast(distance(begin, end)) < + (significant_octets + V4ADDRESS_LEN)) { isc_throw(OutOfRange, "DHCPv4 OptionClasslessStaticRoute " << type_ << " is truncated."); } diff --git a/src/lib/dhcp/option_custom.cc b/src/lib/dhcp/option_custom.cc index 202f802720..60281f90cc 100644 --- a/src/lib/dhcp/option_custom.cc +++ b/src/lib/dhcp/option_custom.cc @@ -308,7 +308,7 @@ OptionCustom::createBuffers(const OptionBuffer& data_buf) { // Our data field requires that there is a certain chunk of // data left in the buffer. If not, option is truncated. - if (std::distance(data, data_buf.end()) < data_size) { + if (static_cast(std::distance(data, data_buf.end())) < data_size) { isc_throw(OutOfRange, "option buffer truncated"); } @@ -325,7 +325,7 @@ OptionCustom::createBuffers(const OptionBuffer& data_buf) { size_t data_size = bufferLength(fields.back(), true, data, data_buf.end()); isc_throw_assert(data_size > 0); - if (std::distance(data, data_buf.end()) < data_size) { + if (static_cast(std::distance(data, data_buf.end())) < data_size) { break; } buffers.push_back(OptionBuffer(data, data + data_size)); @@ -350,7 +350,7 @@ OptionCustom::createBuffers(const OptionBuffer& data_buf) { // Note that data_size returned by getDataTypeLen may be zero // if variable length data is being held by the option but // this will not cause this check to throw exception. - if (std::distance(data, data_buf.end()) < data_size) { + if (static_cast(std::distance(data, data_buf.end())) < data_size) { isc_throw(OutOfRange, "option buffer truncated"); } // For an array of values we are taking different path because @@ -369,7 +369,7 @@ OptionCustom::createBuffers(const OptionBuffer& data_buf) { // data_size. Note that it is ok to truncate the data if and only // if the data buffer is long enough to keep at least one value. // This has been checked above already. - if (std::distance(data, data_buf.end()) < data_size) { + if (static_cast(std::distance(data, data_buf.end())) < data_size) { break; } buffers.push_back(OptionBuffer(data, data + data_size)); @@ -380,7 +380,8 @@ OptionCustom::createBuffers(const OptionBuffer& data_buf) { // getDataTypeLen returns zero for variable size data types // such as strings. Simply take whole buffer. data_size = bufferLength(data_type, false, data, data_buf.end()); - if ((data_size > 0) && (std::distance(data, data_buf.end()) >= data_size)) { + if ((data_size > 0) && + (static_cast(std::distance(data, data_buf.end())) >= data_size)) { buffers.push_back(OptionBuffer(data, data + data_size)); data += data_size; } else { diff --git a/src/lib/dhcp/option_definition.cc b/src/lib/dhcp/option_definition.cc index c41623ddb2..11e36410b7 100644 --- a/src/lib/dhcp/option_definition.cc +++ b/src/lib/dhcp/option_definition.cc @@ -772,7 +772,7 @@ OptionPtr OptionDefinition::factoryIA6(uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) { - if (std::distance(begin, end) < Option6IA::OPTION6_IA_LEN) { + if (static_cast(std::distance(begin, end)) < Option6IA::OPTION6_IA_LEN) { isc_throw(isc::OutOfRange, "input option buffer has invalid size," << " expected at least " << Option6IA::OPTION6_IA_LEN << " bytes"); @@ -785,7 +785,7 @@ OptionPtr OptionDefinition::factoryIAAddr6(uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) { - if (std::distance(begin, end) < Option6IAAddr::OPTION6_IAADDR_LEN) { + if (static_cast(std::distance(begin, end)) < Option6IAAddr::OPTION6_IAADDR_LEN) { isc_throw(isc::OutOfRange, "input option buffer has invalid size, expected at least " << Option6IAAddr::OPTION6_IAADDR_LEN << " bytes"); @@ -799,7 +799,7 @@ OptionPtr OptionDefinition::factoryIAPrefix6(uint16_t type, OptionBufferConstIter begin, OptionBufferConstIter end) { - if (std::distance(begin, end) < Option6IAPrefix::OPTION6_IAPREFIX_LEN) { + if (static_cast(std::distance(begin, end)) < Option6IAPrefix::OPTION6_IAPREFIX_LEN) { isc_throw(isc::OutOfRange, "input option buffer has invalid size, expected at least " << Option6IAPrefix::OPTION6_IAPREFIX_LEN << " bytes"); diff --git a/src/lib/dhcp/option_int.h b/src/lib/dhcp/option_int.h index bc20fd25d8..08048572c0 100644 --- a/src/lib/dhcp/option_int.h +++ b/src/lib/dhcp/option_int.h @@ -146,7 +146,7 @@ public: /// equal to 1, 2 or 4 bytes. The data type is not checked in this function /// because it is checked in a constructor. virtual void unpack(OptionBufferConstIter begin, OptionBufferConstIter end) { - if (distance(begin, end) < sizeof(T)) { + if (static_cast(distance(begin, end)) < sizeof(T)) { isc_throw(OutOfRange, "OptionInt " << getType() << " truncated"); } // @todo consider what to do if buffer is longer than data type. diff --git a/src/lib/dhcp/option_opaque_data_tuples.cc b/src/lib/dhcp/option_opaque_data_tuples.cc index 53a2818182..09900a4b1e 100644 --- a/src/lib/dhcp/option_opaque_data_tuples.cc +++ b/src/lib/dhcp/option_opaque_data_tuples.cc @@ -60,7 +60,7 @@ OptionOpaqueDataTuples::unpack(OptionBufferConstIter begin, // Start reading opaque data. size_t offset = 0; - while (offset < std::distance(begin, end)) { + while (offset < static_cast(std::distance(begin, end))) { // Parse a tuple. OpaqueDataTuple tuple(length_field_type_, begin + offset, end); addTuple(tuple); diff --git a/src/lib/dhcp/option_vendor_class.cc b/src/lib/dhcp/option_vendor_class.cc index 8bb729c24d..c8fb3405c3 100644 --- a/src/lib/dhcp/option_vendor_class.cc +++ b/src/lib/dhcp/option_vendor_class.cc @@ -71,7 +71,7 @@ OptionVendorClass::unpack(OptionBufferConstIter begin, // Start reading opaque data. size_t offset = 0; - while (offset < std::distance(begin, end)) { + while (offset < static_cast(std::distance(begin, end))) { // Parse a tuple. OpaqueDataTuple tuple(OptionDataTypeUtil::getTupleLenFieldType(getUniverse()), begin + offset, end); diff --git a/src/lib/dhcpsrv/cfg_expiration.cc b/src/lib/dhcpsrv/cfg_expiration.cc index 2931740b1d..1246b7944e 100644 --- a/src/lib/dhcpsrv/cfg_expiration.cc +++ b/src/lib/dhcpsrv/cfg_expiration.cc @@ -100,7 +100,7 @@ CfgExpiration::rangeCheck(const int64_t value, const uint64_t max_value, isc_throw(OutOfRange, "value for configuration parameter '" << config_parameter_name << "' must not be negative"); - } else if (value > max_value) { + } else if (static_cast(value) > max_value) { isc_throw(OutOfRange, "out range value '" << value << "' for configuration" " parameter '" << config_parameter_name << "', expected maximum" " value of '" << max_value << "'"); diff --git a/src/lib/dhcpsrv/flq_allocator.cc b/src/lib/dhcpsrv/flq_allocator.cc index b89277a582..379f743a5c 100644 --- a/src/lib/dhcpsrv/flq_allocator.cc +++ b/src/lib/dhcpsrv/flq_allocator.cc @@ -47,7 +47,7 @@ FreeLeaseQueueAllocator::pickAddressInternal(const ClientClasses& client_classes // Let's first iterate over the pools and identify the ones that // meet client class criteria and are not exhausted. std::vector available; - for (auto i = 0; i < pools.size(); ++i) { + for (unsigned i = 0; i < pools.size(); ++i) { // Check if the pool is allowed for the client's classes. if (pools[i]->clientSupported(client_classes)) { // Get or create the pool state. @@ -94,7 +94,7 @@ FreeLeaseQueueAllocator::pickPrefixInternal(const ClientClasses& client_classes, // Let's first iterate over the pools and identify the ones that // meet client class criteria and are not exhausted. std::vector available; - for (auto i = 0; i < pools.size(); ++i) { + for (unsigned i = 0; i < pools.size(); ++i) { // Check if the pool is allowed for the client's classes. if (pools[i]->clientSupported(client_classes)) { if (!Allocator::isValidPrefixPool(prefix_length_match, pools[i], diff --git a/src/lib/dhcpsrv/lease_mgr.cc b/src/lib/dhcpsrv/lease_mgr.cc index 63284c47f9..579b477a37 100644 --- a/src/lib/dhcpsrv/lease_mgr.cc +++ b/src/lib/dhcpsrv/lease_mgr.cc @@ -868,7 +868,7 @@ LeaseMgr::upgradeLease6ExtendedInfo(const Lease6Ptr& lease, } verifying = "relay"; - for (i = 0; i < relay_info->size(); ++i) { + for (i = 0; static_cast(i) < relay_info->size(); ++i) { ElementPtr relay = relay_info->getNonConst(i); if (!relay) { mutable_isc->remove("relay-info"); @@ -943,7 +943,7 @@ LeaseMgr::upgradeLease6ExtendedInfo(const Lease6Ptr& lease, } verifying = "relay"; - for (i = 0; i < relay_info->size(); ++i) { + for (i = 0; static_cast(i) < relay_info->size(); ++i) { ElementPtr relay = relay_info->getNonConst(i); if (!upgraded && !relay) { mutable_isc->remove("relay-info"); @@ -1235,7 +1235,7 @@ LeaseMgr::addExtendedInfo6(const Lease6Ptr& lease) { return (added); } - for (int i = 0; i < relay_info->size(); ++i) { + for (unsigned i = 0; i < relay_info->size(); ++i) { ConstElementPtr relay = relay_info->get(i); if (!relay || (relay->getType() != Element::map) || relay->empty()) { continue; diff --git a/src/lib/dhcpsrv/memfile_lease_limits.cc b/src/lib/dhcpsrv/memfile_lease_limits.cc index f972eb6c9d..881b140643 100644 --- a/src/lib/dhcpsrv/memfile_lease_limits.cc +++ b/src/lib/dhcpsrv/memfile_lease_limits.cc @@ -83,7 +83,7 @@ ClassLeaseCounter::adjustClassCounts(ConstElementPtr classes, int offset, return; } - for (int i = 0; i < classes->size(); ++i) { + for (unsigned i = 0; i < classes->size(); ++i) { std::string class_name = classes->get(i)->stringValue(); adjustClassCount(class_name, offset, ltype); } diff --git a/src/lib/dhcpsrv/memfile_lease_mgr.cc b/src/lib/dhcpsrv/memfile_lease_mgr.cc index 046cd0bebc..7e9630d53d 100644 --- a/src/lib/dhcpsrv/memfile_lease_mgr.cc +++ b/src/lib/dhcpsrv/memfile_lease_mgr.cc @@ -1411,7 +1411,8 @@ Memfile_LeaseMgr::getLeases4Internal(const asiolink::IOAddress& lower_bound_addr // Return all other leases being within the page size. for (auto lease = lb; - (lease != idx.end()) && (std::distance(lb, lease) < page_size.page_size_); + (lease != idx.end()) && + (static_cast(std::distance(lb, lease)) < page_size.page_size_); ++lease) { collection.push_back(Lease4Ptr(new Lease4(**lease))); } @@ -1686,7 +1687,8 @@ Memfile_LeaseMgr::getLeases6Internal(const asiolink::IOAddress& lower_bound_addr // Return all other leases being within the page size. for (auto lease = lb; - (lease != idx.end()) && (std::distance(lb, lease) < page_size.page_size_); + (lease != idx.end()) && + (static_cast(std::distance(lb, lease)) < page_size.page_size_); ++lease) { collection.push_back(Lease6Ptr(new Lease6(**lease))); } @@ -1789,8 +1791,9 @@ Memfile_LeaseMgr::getExpiredLeases4Internal(Lease4Collection& expired_leases, // Copy only the number of leases indicated by the max_leases parameter. for (Lease4StorageExpirationIndex::const_iterator lease = index.begin(); - (lease != ub) && ((max_leases == 0) || (std::distance(index.begin(), lease) < - max_leases)); + (lease != ub) && + ((max_leases == 0) || + (static_cast(std::distance(index.begin(), lease)) < max_leases)); ++lease) { expired_leases.push_back(Lease4Ptr(new Lease4(**lease))); } @@ -1825,8 +1828,9 @@ Memfile_LeaseMgr::getExpiredLeases6Internal(Lease6Collection& expired_leases, // Copy only the number of leases indicated by the max_leases parameter. for (Lease6StorageExpirationIndex::const_iterator lease = index.begin(); - (lease != ub) && ((max_leases == 0) || (std::distance(index.begin(), lease) < - max_leases)); + (lease != ub) && + ((max_leases == 0) || + (static_cast(std::distance(index.begin(), lease)) < max_leases)); ++lease) { expired_leases.push_back(Lease6Ptr(new Lease6(**lease))); } @@ -2718,7 +2722,7 @@ Memfile_LeaseMgr::checkLimits4(isc::data::ConstElementPtr const& user_context) c // an "address-limit", check its value against the class's lease count. ConstElementPtr classes = limits->get("client-classes"); if (classes) { - for (int i = 0; i < classes->size(); ++i) { + for (unsigned i = 0; i < classes->size(); ++i) { ConstElementPtr class_elem = classes->get(i); // Get class name. ConstElementPtr name_elem = class_elem->get("name"); @@ -2776,7 +2780,7 @@ Memfile_LeaseMgr::checkLimits4(isc::data::ConstElementPtr const& user_context) c } // If we're over the limit, return the error. - if (lease_count >= limit) { + if (static_cast(lease_count) >= limit) { std::ostringstream ss; ss << "address limit " << limit << " for subnet ID " << subnet_id << ", current lease count " << lease_count; @@ -2805,7 +2809,7 @@ Memfile_LeaseMgr::checkLimits6(isc::data::ConstElementPtr const& user_context) c // class lease count. ConstElementPtr classes = limits->get("client-classes"); if (classes) { - for (int i = 0; i < classes->size(); ++i) { + for (unsigned i = 0; i < classes->size(); ++i) { ConstElementPtr class_elem = classes->get(i); // Get class name. ConstElementPtr name_elem = class_elem->get("name"); @@ -2877,7 +2881,7 @@ Memfile_LeaseMgr::checkLimits6(isc::data::ConstElementPtr const& user_context) c } // If we're over the limit, return the error. - if (lease_count >= limit) { + if (static_cast(lease_count) >= limit) { std::ostringstream ss; ss << (ltype == Lease::TYPE_NA ? "address" : "prefix") << " limit " << limit << " for subnet ID " << subnet_id diff --git a/src/lib/dhcpsrv/packet_fuzzer.cc b/src/lib/dhcpsrv/packet_fuzzer.cc index b4a16468a2..2461d00ab1 100644 --- a/src/lib/dhcpsrv/packet_fuzzer.cc +++ b/src/lib/dhcpsrv/packet_fuzzer.cc @@ -180,7 +180,7 @@ PacketFuzzer::transfer(uint8_t const* data, size_t size) const { // Now send the data to the UDP port on which Kea is listening. // Send the data to the main Kea thread. Limit the size of the // packets that can be sent. - size_t send_len = (length < MAX_SEND_SIZE) ? length : MAX_SEND_SIZE; + size_t send_len = (size < MAX_SEND_SIZE) ? size : MAX_SEND_SIZE; ssize_t sent = sendto(sockfd_, buf, send_len, 0, sockaddr_ptr_, sockaddr_len_); if (sent < 0) { diff --git a/src/lib/dhcpsrv/random_allocator.cc b/src/lib/dhcpsrv/random_allocator.cc index 3c59bb39d8..0a2ba39694 100644 --- a/src/lib/dhcpsrv/random_allocator.cc +++ b/src/lib/dhcpsrv/random_allocator.cc @@ -36,7 +36,7 @@ RandomAllocator::pickAddressInternal(const ClientClasses& client_classes, // ones. std::vector available; std::vector exhausted; - for (auto i = 0; i < pools.size(); ++i) { + for (unsigned i = 0; i < pools.size(); ++i) { // Check if the pool is allowed for the client's classes. if (pools[i]->clientSupported(client_classes)) { // Get or create the pool state. @@ -99,7 +99,7 @@ RandomAllocator::pickPrefixInternal(const ClientClasses& client_classes, // ones. std::vector available; std::vector exhausted; - for (auto i = 0; i < pools.size(); ++i) { + for (unsigned i = 0; i < pools.size(); ++i) { // Check if the pool is allowed for the client's classes. if (pools[i]->clientSupported(client_classes)) { if (!Allocator::isValidPrefixPool(prefix_length_match, pools[i], diff --git a/src/lib/dns/labelsequence.cc b/src/lib/dns/labelsequence.cc index c0b8778b4c..bbdc71ca58 100644 --- a/src/lib/dns/labelsequence.cc +++ b/src/lib/dns/labelsequence.cc @@ -133,7 +133,8 @@ LabelSequence::serialize(void* buf, size_t buf_len) const { std::memcpy(bp, &data_[offsets_[first_label_]], ndata_len); bp += ndata_len; - isc_throw_assert(bp - reinterpret_cast(buf) == expected_size); + isc_throw_assert(bp - reinterpret_cast(buf) == + static_cast(expected_size)); } bool diff --git a/src/lib/dns/message.cc b/src/lib/dns/message.cc index 913240c583..438b15fd13 100644 --- a/src/lib/dns/message.cc +++ b/src/lib/dns/message.cc @@ -154,7 +154,7 @@ MessageImpl::init() { edns_ = EDNSPtr(); tsig_rr_ = ConstTSIGRecordPtr(); - for (int i = 0; i < NUM_SECTIONS; ++i) { + for (unsigned int i = 0; i < NUM_SECTIONS; ++i) { counts_[i] = 0; } @@ -491,7 +491,7 @@ Message::getTSIGRecord() const { unsigned int Message::getRRCount(const Section section) const { - if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { + if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { isc_throw(OutOfRange, "Invalid message section: " << static_cast(section)); } return (impl_->counts_[section]); @@ -507,7 +507,7 @@ Message::addRRset(const Section section, RRsetPtr rrset) { isc_throw(InvalidMessageOperation, "addRRset performed in non-render mode"); } - if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { + if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { isc_throw(OutOfRange, "Invalid message section: " << static_cast(section)); } @@ -519,7 +519,7 @@ Message::addRRset(const Section section, RRsetPtr rrset) { bool Message::hasRRset(const Section section, const Name& name, const RRClass& rrclass, const RRType& rrtype) const { - if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { + if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { isc_throw(OutOfRange, "Invalid message section: " << static_cast(section)); } @@ -542,7 +542,7 @@ Message::hasRRset(const Section section, const RRsetPtr& rrset) const { bool Message::removeRRset(const Section section, RRsetIterator& iterator) { - if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { + if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { isc_throw(OutOfRange, "Invalid message section: " << static_cast(section)); } @@ -570,7 +570,7 @@ Message::clearSection(const Section section) { isc_throw(InvalidMessageOperation, "clearSection performed in non-render mode"); } - if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { + if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { isc_throw(OutOfRange, "Invalid message section: " << static_cast(section)); } if (section == Message::SECTION_QUESTION) { @@ -658,7 +658,7 @@ MessageImpl::parseQuestion(InputBuffer& buffer) { unsigned int added = 0; for (unsigned int count = 0; - count < counts_[Message::SECTION_QUESTION]; + static_cast(count) < counts_[Message::SECTION_QUESTION]; ++count) { const Name name(buffer); @@ -732,13 +732,15 @@ struct MatchRR { int MessageImpl::parseSection(const Message::Section section, InputBuffer& buffer, Message::ParseOptions options) { - if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { + if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { isc_throw(OutOfRange, "Invalid message section: " << static_cast(section)); } unsigned int added = 0; - for (unsigned int count = 0; count < counts_[section]; ++count) { + for (unsigned int count = 0; + static_cast(count) < counts_[section]; + ++count) { // We need to remember the start position for TSIG processing const size_t start_position = buffer.getPosition(); @@ -847,7 +849,7 @@ MessageImpl::addTSIG(Message::Section section, unsigned int count, isc_throw(DNSMessageFORMERR, "TSIG RR found in an invalid section"); } - if (count != counts_[section] - 1) { + if (static_cast(count) != counts_[section] - 1) { isc_throw(DNSMessageFORMERR, "TSIG RR is not the last record"); } // This check will never fail as the multiple TSIG RR case is @@ -991,7 +993,7 @@ Message::clear(Mode mode) { void Message::appendSection(const Section section, const Message& source) { - if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { + if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { isc_throw(OutOfRange, "Invalid message section: " << static_cast(section)); } @@ -1135,7 +1137,7 @@ Message::endQuestion() const { /// const SectionIterator Message::beginSection(const Section section) const { - if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { + if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { isc_throw(OutOfRange, "Invalid message section: " << static_cast(section)); } if (section == SECTION_QUESTION) { @@ -1148,7 +1150,7 @@ Message::beginSection(const Section section) const { const SectionIterator Message::endSection(const Section section) const { - if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { + if (static_cast(section) >= MessageImpl::NUM_SECTIONS) { isc_throw(OutOfRange, "Invalid message section: " << static_cast(section)); } if (section == SECTION_QUESTION) { diff --git a/src/lib/eval/token.cc b/src/lib/eval/token.cc index 3d0f719283..ab5d031d4d 100644 --- a/src/lib/eval/token.cc +++ b/src/lib/eval/token.cc @@ -932,7 +932,7 @@ TokenSplit::evaluate(Pkt& pkt, ValueStack& values) { boost::algorithm::token_compress_off); // Range check the field. - if (field < 1 || field > fields.size()) { + if (field < 1 || static_cast(field) > fields.size()) { // Push an empty string if field is out of range. values.push(""); @@ -1367,7 +1367,7 @@ TokenVendorClass::evaluate(Pkt& pkt, ValueStack& values) { case DATA: { size_t max = vendor->getTuplesNum(); - if (index_ + 1 > max) { + if (static_cast(index_ + 1) > max) { // The index specified is out of bounds, e.g. there are only // 2 tuples and index specified is 5. LOG_DEBUG(eval_logger, EVAL_DBG_STACK, EVAL_DEBUG_VENDOR_CLASS_DATA_NOT_FOUND) diff --git a/src/lib/hooks/callout_manager.cc b/src/lib/hooks/callout_manager.cc index a4392a33b3..90d92f029e 100644 --- a/src/lib/hooks/callout_manager.cc +++ b/src/lib/hooks/callout_manager.cc @@ -95,7 +95,8 @@ CalloutManager::registerCallout(const std::string& name, bool CalloutManager::calloutsPresent(int hook_index) const { // Validate the hook index. - if ((hook_index < 0) || (hook_index >= hook_vector_.size())) { + if ((hook_index < 0) || + (static_cast(hook_index) >= hook_vector_.size())) { isc_throw(NoSuchHook, "hook index " << hook_index << " is not valid for the list of registered hooks"); } @@ -242,7 +243,7 @@ CalloutManager::deregisterCallout(const std::string& name, CalloutPtr callout, int hook_index = server_hooks_.getIndex(name); // New hooks can have been registered since the manager was constructed. - if (hook_index >= hook_vector_.size()) { + if (static_cast(hook_index) >= hook_vector_.size()) { return (false); } @@ -340,7 +341,7 @@ CalloutManager::registerCommandHook(const std::string& command_name) { void CalloutManager::ensureHookLibsVectorSize() { ServerHooks& hooks = ServerHooks::getServerHooks(); - if (hooks.getCount() > hook_vector_.size()) { + if (static_cast(hooks.getCount()) > hook_vector_.size()) { // Uh oh, there are more hook points that our vector allows. hook_vector_.resize(hooks.getCount()); } diff --git a/src/lib/hooks/library_handle.cc b/src/lib/hooks/library_handle.cc index 6224026d77..67441faa5f 100644 --- a/src/lib/hooks/library_handle.cc +++ b/src/lib/hooks/library_handle.cc @@ -83,7 +83,7 @@ LibraryHandle::getParameters() { index = callout_manager_.getLibraryIndex(); } - if ((index > libinfo.size()) || (index <= 0)) { + if ((index > static_cast(libinfo.size())) || (index <= 0)) { // Something is very wrong here. The library index is out of bounds. // However, this is user facing interface, so we should not throw here. return (isc::data::ConstElementPtr()); diff --git a/src/lib/pgsql/pgsql_connection.cc b/src/lib/pgsql/pgsql_connection.cc index e5954cd1f1..d09ed7042d 100644 --- a/src/lib/pgsql/pgsql_connection.cc +++ b/src/lib/pgsql/pgsql_connection.cc @@ -604,7 +604,7 @@ PgSqlConnection::executePreparedStatement(PgSqlTaggedStatement& statement, const PsqlBindArray& in_bindings) { checkUnusable(); - if (statement.nbparams != in_bindings.size()) { + if (static_cast(statement.nbparams) != in_bindings.size()) { isc_throw (InvalidOperation, "executePreparedStatement:" << " expected: " << statement.nbparams << " parameters, given: " << in_bindings.size() diff --git a/src/lib/pgsql/pgsql_exchange.cc b/src/lib/pgsql/pgsql_exchange.cc index d203714108..bcb9219979 100644 --- a/src/lib/pgsql/pgsql_exchange.cc +++ b/src/lib/pgsql/pgsql_exchange.cc @@ -295,7 +295,7 @@ PsqlBindArray::toText() const { return ("bindarray is empty"); } - for (int i = 0; i < values_.size(); ++i) { + for (size_t i = 0; i < values_.size(); ++i) { stream << i << " : "; if (lengths_[i] == 0) { diff --git a/src/lib/testutils/log_utils.cc b/src/lib/testutils/log_utils.cc index 7cc53b9b5d..0064a1708e 100644 --- a/src/lib/testutils/log_utils.cc +++ b/src/lib/testutils/log_utils.cc @@ -49,7 +49,7 @@ bool LogContentTest::checkFile() { ifstream file(LOG_FILE); EXPECT_TRUE(file.is_open()); string line, exp_line; - int i = 0; + unsigned i = 0; bool found = true; using namespace std; diff --git a/src/lib/testutils/unix_control_client.cc b/src/lib/testutils/unix_control_client.cc index c980aba150..1d1fdc7540 100644 --- a/src/lib/testutils/unix_control_client.cc +++ b/src/lib/testutils/unix_control_client.cc @@ -91,7 +91,7 @@ bool UnixControlClient::sendCommand(const std::string& command) { } // Send command int bytes_sent = send(socket_fd_, command.c_str(), command.length(), 0); - if (bytes_sent < command.length()) { + if (bytes_sent < static_cast(command.length())) { const char* errmsg = strerror(errno); ADD_FAILURE() << "Failed to send " << command.length() << " bytes, send() returned " << bytes_sent diff --git a/src/lib/yang/adaptor.cc b/src/lib/yang/adaptor.cc index b099c5a6ec..389e26fc26 100644 --- a/src/lib/yang/adaptor.cc +++ b/src/lib/yang/adaptor.cc @@ -153,7 +153,7 @@ void applyDelete(ConstElementPtr key, ElementPtr scope) { return; } else if (key->getType() == Element::integer) { int index = key->intValue(); - if ((index >= 0) && (index < scope->size())) { + if ((index >= 0) && (static_cast(index) < scope->size())) { scope->remove(index); } } else if (key->getType() == Element::map) { @@ -166,7 +166,7 @@ void applyDelete(ConstElementPtr key, ElementPtr scope) { if (name.empty()) { return; } - for (int i = 0; i < scope->size(); ++i) { + for (unsigned i = 0; i < scope->size(); ++i) { ElementPtr item = scope->getNonConst(i); if (!item || (item->getType() != Element::map)) { continue; @@ -283,7 +283,7 @@ void applyDown(ConstElementPtr path, ConstElementPtr actions, ElementPtr scope, for (ElementPtr& down : downs) { applyDown(path, actions, down, next); } - } else if ((index >= 0) && (index < scope->size())) { + } else if ((index >= 0) && (static_cast(index) < scope->size())) { applyDown(path, actions, scope->getNonConst(index), next); } }