]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3119] Fixed some coverity reported defects
authorFrancis Dupont <fdupont@isc.org>
Mon, 4 Dec 2023 09:18:55 +0000 (10:18 +0100)
committerRazvan Becheriu <razvan@isc.org>
Mon, 22 Jan 2024 15:33:26 +0000 (17:33 +0200)
src/bin/dhcp6/dhcp6_srv.cc
src/hooks/dhcp/flex_option/flex_option.h
src/lib/cc/data.cc
src/lib/dhcpsrv/cfg_option.cc
src/lib/dhcpsrv/parsers/client_class_def_parser.cc
src/lib/dhcpsrv/srv_config.cc
src/lib/dhcpsrv/subnet.cc
src/lib/process/redact_config.cc
src/lib/stats/context.cc

index 60324d0c3f0c93b442abc00807ce45e969ca298b..6024cdd2dffc7403f4c78b36feaaf057ef642797 100644 (file)
@@ -1426,7 +1426,7 @@ Dhcpv6Srv::buildCfgOptionList(const Pkt6Ptr& question,
     // Secondly, pool specific options. Pools are defined within a subnet, so
     // if there is no subnet, there is nothing to do.
     if (ctx.subnet_) {
-        for (auto resource : ctx.allocated_resources_) {
+        for (const auto& resource : ctx.allocated_resources_) {
             PoolPtr pool =
                 ctx.subnet_->getPool(resource.getPrefixLength() == 128 ?
                                      Lease::TYPE_NA : Lease::TYPE_PD,
@@ -4211,7 +4211,7 @@ Dhcpv6Srv::processDhcp4Query(const Pkt6Ptr& dhcp4_query) {
 
 void Dhcpv6Srv::classifyByVendor(const Pkt6Ptr& pkt) {
     OptionVendorClassPtr vclass;
-    for (auto opt : pkt->getOptions(D6O_VENDOR_CLASS)) {
+    for (const auto& opt : pkt->getOptions(D6O_VENDOR_CLASS)) {
         vclass = boost::dynamic_pointer_cast<OptionVendorClass>(opt.second);
         if (!vclass || vclass->getTuplesNum() == 0) {
             continue;
@@ -4333,7 +4333,7 @@ Dhcpv6Srv::requiredClassify(const Pkt6Ptr& pkt, AllocEngine::ClientContext6& ctx
         }
 
         // And finish by pools
-        for (auto resource : ctx.allocated_resources_) {
+        for (const auto& resource : ctx.allocated_resources_) {
             PoolPtr pool =
                 ctx.subnet_->getPool(resource.getPrefixLength() == 128 ?
                                      Lease::TYPE_NA : Lease::TYPE_PD,
index bda8ca186ef8d547213549d731a78075f6916c21..e26b437ed9554492dd52cd2480d67e8a0807afd8 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2022 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2019-2023 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -375,7 +375,7 @@ public:
             }
         }
         for (auto pair : getSubOptionConfigMap()) {
-            for (auto sub_pair : pair.second) {
+            for (const auto& sub_pair : pair.second) {
                 const SubOptionConfigPtr& sub_cfg = sub_pair.second;
                 uint16_t sub_code = sub_cfg->getCode();
                 uint16_t opt_code = sub_cfg->getContainerCode();
index 12d59b44ea91da1fac51a2aa11635042d89d8e86..9b13bcea5ca4e9197035cb3a6627279ddf54216e 100644 (file)
@@ -1178,7 +1178,7 @@ removeIdentical(ConstElementPtr a, ConstElementPtr b) {
         isc_throw(TypeError, "Non-map Elements passed to removeIdentical");
     }
 
-    for (auto kv : a->mapValue()) {
+    for (const auto& kv : a->mapValue()) {
         auto key = kv.first;
         if (!b->contains(key) ||
             !a->get(key)->equals(*b->get(key))) {
@@ -1196,7 +1196,7 @@ merge(ElementPtr element, ConstElementPtr other) {
         isc_throw(TypeError, "merge arguments not MapElements");
     }
 
-    for (auto kv : other->mapValue()) {
+    for (const auto& kv : other->mapValue()) {
         auto key = kv.first;
         auto value = kv.second;
         if (value && value->getType() != Element::null) {
@@ -1517,7 +1517,7 @@ isEquivalent0(ConstElementPtr a, ConstElementPtr b, unsigned level) {
             return (false);
         }
         // iterate on the first map
-        for (auto kv : a->mapValue()) {
+        for (const auto& kv : a->mapValue()) {
             // get the b value for the given keyword and recurse
             ConstElementPtr item = b->get(kv.first);
             if (!item || !isEquivalent0(kv.second, item, level - 1)) {
index 5999b9079fb16a3d2fff161b3a8a3b7edde392f9..9a241dfa9fe9bfd576afdf5d934cd083cd6fed26 100644 (file)
@@ -162,7 +162,7 @@ CfgOption::createOptions(CfgOptionDefPtr cfg_def) {
     // Iterate over all the option descriptors in
     // all the spaces and instantiate the options
     // based on the given definitions.
-    for (auto space : getOptionSpaceNames()) {
+    for (const auto& space : getOptionSpaceNames()) {
         for (auto opt_desc : *(getAll(space))) {
             if (createDescriptorOption(cfg_def, space, opt_desc)) {
                 // Option was recreated, let's replace the descriptor.
@@ -372,7 +372,7 @@ CfgOption::del(const std::string& option_space, const uint16_t option_code) {
         (option_space != DHCP6_OPTION_SPACE)) {
         // For each option space name iterate over the existing options.
         auto option_space_names = getOptionSpaceNames();
-        for (auto option_space_from_list : option_space_names) {
+        for (const auto& option_space_from_list : option_space_names) {
             // Get all options within the particular option space.
             auto options_in_space = getAll(option_space_from_list);
             for (auto option_it = options_in_space->begin();
index 291632bae06a5b3ef95bedf681f21dc737a957cc..a62af4d9f781bb866e9df48c8d1bc705e8d9519d 100644 (file)
@@ -251,7 +251,7 @@ ClientClassDefParser::parse(ClientClassDictionaryPtr& class_dictionary,
     }
 
     // Sanity checks on built-in classes
-    for (auto bn : builtinNames) {
+    for (const auto& bn : builtinNames) {
         if (name == bn) {
             if (required) {
                 isc_throw(DhcpConfigError, "built-in class '" << name
index 66cb9b2511f6f418f6f791661c9283f440bb10bf..750b0797c963a915f5c4f4c0b1f6547df2d010a0 100644 (file)
@@ -333,7 +333,7 @@ SrvConfig::applyDefaultsConfiguredGlobals(const SimpleDefaults& defaults) {
     const Element::Position pos("<default-value>", 0, 0);
 
     // Let's go over all parameters we have defaults for.
-    for (auto def_value : defaults) {
+    for (const auto& def_value : defaults) {
 
         // Try if such a parameter is there. If it is, let's
         // skip it, because user knows best *cough*.
index 2e480d474b265370005db36896d8ce277ca7ea27..d0a380d7a20a6ebf459cbca4da27ac2b94016676 100644 (file)
@@ -442,7 +442,7 @@ const PoolPtr Subnet::getPool(Lease::Type type, const isc::asiolink::IOAddress&
 
 void
 Subnet::initAllocatorsAfterConfigure() {
-    for (auto allocator : allocators_) {
+    for (const auto& allocator : allocators_) {
         allocator.second->initAfterConfigure();
     }
 }
index 16bba0f3ceb80105096080bce5f1c975825b3311..686620e3242bbfb5a936a9ff2d8ffa3eae469985 100644 (file)
@@ -46,7 +46,7 @@ redact(ElementPtrType const& element, list<string> json_path) {
         if (next_key == "*" || json_path.empty()) {
             // Then iterate through all the children.
             result = Element::createMap();
-            for (auto kv : element->mapValue()) {
+            for (const auto& kv : element->mapValue()) {
                 std::string const& key(kv.first);
                 ConstElementPtr const& value(kv.second);
 
index 697b3de7e3f0980c890a410a2ec40a3c4677b8d0..3675df9fbe214ba78bb2a6bb4eec0d8e4126ae81 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2023 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -80,7 +80,7 @@ StatContext::getAll() const {
 void
 StatContext::setMaxSampleCountAll(uint32_t max_samples) {
     // Let's iterate over all stored statistics...
-    for (auto s : stats_) {
+    for (const auto& s : stats_) {
         // ... and set count limit for each statistic.
         s.second->setMaxSampleCount(max_samples);
     }