From: Stephen Morris Date: Mon, 10 Dec 2012 12:06:06 +0000 (+0000) Subject: [2546] Correct issues raised by cppcheck X-Git-Tag: bind10-1.0.0-beta-release~34 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e4e8de317591b5ac9fec818693fb2cdc5ce9e2a3;p=thirdparty%2Fkea.git [2546] Correct issues raised by cppcheck Mostly adding "const" to methods that don't change the class, but also correcting a few other points that were raised. --- diff --git a/src/lib/dhcp/option.h b/src/lib/dhcp/option.h index a6b062286e..22ac2913f7 100644 --- a/src/lib/dhcp/option.h +++ b/src/lib/dhcp/option.h @@ -152,7 +152,7 @@ public: /// @brief returns option universe (V4 or V6) /// /// @return universe type - Universe getUniverse() { return universe_; }; + Universe getUniverse() const { return universe_; }; /// @brief Writes option in wire-format to a buffer. /// @@ -197,7 +197,7 @@ public: /// Returns option type (0-255 for DHCPv4, 0-65535 for DHCPv6) /// /// @return option type - uint16_t getType() { return (type_); } + uint16_t getType() const { return (type_); } /// Returns length of the complete option (data length + DHCPv4/DHCPv6 /// option header) diff --git a/src/lib/dhcp/option4_addrlst.h b/src/lib/dhcp/option4_addrlst.h index b266cbf0a9..927f75b930 100644 --- a/src/lib/dhcp/option4_addrlst.h +++ b/src/lib/dhcp/option4_addrlst.h @@ -111,10 +111,10 @@ public: /// We return a copy of our list. Although this includes overhead, /// it also makes this list safe to use after this option object /// is no longer available. As options are expected to hold only - /// a couple (1-3) addresses, the overhead is not that big. + /// a few (1-3) addresses, the overhead is not that big. /// /// @return address container with addresses - AddressContainer getAddresses() { return addrs_; }; + AddressContainer getAddresses() const { return addrs_; }; /// @brief Sets addresses list. /// diff --git a/src/lib/dhcp/option6_addrlst.h b/src/lib/dhcp/option6_addrlst.h index b9c0debc06..8327201e32 100644 --- a/src/lib/dhcp/option6_addrlst.h +++ b/src/lib/dhcp/option6_addrlst.h @@ -82,10 +82,10 @@ public: /// We return a copy of our list. Although this includes overhead, /// it also makes this list safe to use after this option object /// is no longer available. As options are expected to hold only - /// a couple (1-3) addresses, the overhead is not that big. + /// a few (1-3) addresses, the overhead is not that big. /// /// @return address container with addresses - AddressContainer getAddresses() { return addrs_; }; + AddressContainer getAddresses() const { return addrs_; }; // returns data length (data length + DHCPv4/DHCPv6 option header) virtual uint16_t len(); diff --git a/src/lib/dhcp/option_data_types.cc b/src/lib/dhcp/option_data_types.cc index 46aa663f38..de09bc4c45 100644 --- a/src/lib/dhcp/option_data_types.cc +++ b/src/lib/dhcp/option_data_types.cc @@ -209,7 +209,7 @@ OptionDataTypeUtil::writeBool(const bool value, std::string OptionDataTypeUtil::readString(const std::vector& buf) { std::string value; - if (buf.size() > 0) { + if (!buf.empty()) { value.insert(value.end(), buf.begin(), buf.end()); } return (value); diff --git a/src/lib/dhcp/option_definition.cc b/src/lib/dhcp/option_definition.cc index 58d0c4bae8..f1e89e262d 100644 --- a/src/lib/dhcp/option_definition.cc +++ b/src/lib/dhcp/option_definition.cc @@ -144,7 +144,7 @@ OptionDefinition::optionFactory(Option::Universe u, uint16_t type, OptionBuffer buf; if (!array_type_ && type_ != OPT_RECORD_TYPE) { - if (values.size() == 0) { + if (values.empty()) { isc_throw(InvalidOptionValue, "no option value specified"); } writeToBuffer(values[0], type_, buf); diff --git a/src/lib/dhcp/pkt4.cc b/src/lib/dhcp/pkt4.cc index 5be82113a9..a232d020a0 100644 --- a/src/lib/dhcp/pkt4.cc +++ b/src/lib/dhcp/pkt4.cc @@ -228,7 +228,7 @@ Pkt4::setHWAddr(uint8_t hType, uint8_t hlen, isc_throw(OutOfRange, "Hardware address (len=" << hlen << " too long. Max " << MAX_CHADDR_LEN << " supported."); } - if ( (macAddr.size() == 0) && (hlen > 0) ) { + if (macAddr.empty() && (hlen > 0) ) { isc_throw(OutOfRange, "Invalid HW Address specified"); } diff --git a/src/lib/dhcp/pkt4.h b/src/lib/dhcp/pkt4.h index e09069cc36..9c0335128c 100644 --- a/src/lib/dhcp/pkt4.h +++ b/src/lib/dhcp/pkt4.h @@ -367,7 +367,7 @@ public: /// @brief Returns remote address /// /// @return remote address - const isc::asiolink::IOAddress& getRemoteAddr() { + const isc::asiolink::IOAddress& getRemoteAddr() const { return (remote_addr_); } @@ -381,7 +381,7 @@ public: /// @brief Returns local address. /// /// @return local address - const isc::asiolink::IOAddress& getLocalAddr() { + const isc::asiolink::IOAddress& getLocalAddr() const { return (local_addr_); } @@ -393,7 +393,7 @@ public: /// @brief Returns local port. /// /// @return local port - uint16_t getLocalPort() { return (local_port_); } + uint16_t getLocalPort() const { return (local_port_); } /// @brief Sets remote port. /// @@ -403,7 +403,7 @@ public: /// @brief Returns remote port. /// /// @return remote port - uint16_t getRemotePort() { return (remote_port_); } + uint16_t getRemotePort() const { return (remote_port_); } /// @brief Update packet timestamp. /// diff --git a/src/lib/dhcp/pkt6.h b/src/lib/dhcp/pkt6.h index 5782737dc9..ac5e7875fa 100644 --- a/src/lib/dhcp/pkt6.h +++ b/src/lib/dhcp/pkt6.h @@ -127,7 +127,7 @@ public: /// Returns message type (e.g. 1 = SOLICIT) /// /// @return message type - uint8_t getType() { return (msg_type_); } + uint8_t getType() const { return (msg_type_); } /// Sets message type (e.g. 1 = SOLICIT) /// @@ -180,7 +180,9 @@ public: /// @brief Returns remote address /// /// @return remote address - const isc::asiolink::IOAddress& getRemoteAddr() { return (remote_addr_); } + const isc::asiolink::IOAddress& getRemoteAddr() const { + return (remote_addr_); + } /// @brief Sets local address. /// @@ -190,7 +192,9 @@ public: /// @brief Returns local address. /// /// @return local address - const isc::asiolink::IOAddress& getLocalAddr() { return (local_addr_); } + const isc::asiolink::IOAddress& getLocalAddr() const { + return (local_addr_); + } /// @brief Sets local port. /// @@ -200,7 +204,7 @@ public: /// @brief Returns local port. /// /// @return local port - uint16_t getLocalPort() { return (local_port_); } + uint16_t getLocalPort() const { return (local_port_); } /// @brief Sets remote port. /// @@ -210,7 +214,7 @@ public: /// @brief Returns remote port. /// /// @return remote port - uint16_t getRemotePort() { return (remote_port_); } + uint16_t getRemotePort() const { return (remote_port_); } /// @brief Sets interface index. /// diff --git a/src/lib/dhcpsrv/lease_mgr.h b/src/lib/dhcpsrv/lease_mgr.h index fe819bac16..d60a23d159 100644 --- a/src/lib/dhcpsrv/lease_mgr.h +++ b/src/lib/dhcpsrv/lease_mgr.h @@ -118,32 +118,6 @@ struct Lease4 { /// @brief Maximum size of a hardware address static const size_t HWADDR_MAX = 20; - /// @brief Constructor - /// - /// @param addr IPv4 address as unsigned 32-bit integer in network byte - /// order. - /// @param hwaddr Hardware address buffer - /// @param hwaddr_len Length of hardware address buffer - /// @param clientid Client identification buffer - /// @param clientid_len Length of client identification buffer - /// @param valid_lft Lifetime of the lease - /// @param cltt Client last transmission time - /// @param subnet_id Subnet identification - Lease4(uint32_t addr, const uint8_t* hwaddr, size_t hwaddr_len, - const uint8_t* clientid, size_t clientid_len, uint32_t valid_lft, - time_t cltt, uint32_t subnet_id) - : addr_(addr), ext_(0), hwaddr_(hwaddr, hwaddr + hwaddr_len), - client_id_(new ClientId(clientid, clientid_len)), t1_(0), t2_(0), - valid_lft_(valid_lft), cltt_(cltt), subnet_id_(subnet_id), - fixed_(false), hostname_(), fqdn_fwd_(false), fqdn_rev_(false), - comments_() - {} - - /// @brief Default Constructor - /// - /// Initialize fields that don't have a default constructor. - Lease4() : addr_(0) {} - /// IPv4 address isc::asiolink::IOAddress addr_; @@ -227,6 +201,33 @@ struct Lease4 { /// system administrator. std::string comments_; + /// @brief Constructor + /// + /// @param addr IPv4 address as unsigned 32-bit integer in network byte + /// order. + /// @param hwaddr Hardware address buffer + /// @param hwaddr_len Length of hardware address buffer + /// @param clientid Client identification buffer + /// @param clientid_len Length of client identification buffer + /// @param valid_lft Lifetime of the lease + /// @param cltt Client last transmission time + /// @param subnet_id Subnet identification + Lease4(uint32_t addr, const uint8_t* hwaddr, size_t hwaddr_len, + const uint8_t* clientid, size_t clientid_len, uint32_t valid_lft, + time_t cltt, uint32_t subnet_id) + : addr_(addr), ext_(0), hwaddr_(hwaddr, hwaddr + hwaddr_len), + client_id_(new ClientId(clientid, clientid_len)), t1_(0), t2_(0), + valid_lft_(valid_lft), cltt_(cltt), subnet_id_(subnet_id), + fixed_(false), hostname_(), fqdn_fwd_(false), fqdn_rev_(false), + comments_() + {} + + /// @brief Default Constructor + /// + /// Initialize fields that don't have a default constructor. + Lease4() : addr_(0), fixed_(false), fqdn_fwd_(false), fqdn_rev_(false) + {} + /// @brief Compare two leases for equality /// /// @param other lease6 object with which to compare @@ -265,11 +266,6 @@ struct Lease6 { LEASE_IA_PD /// the lease contains IPv6 prefix (for prefix delegation) } LeaseType; - /// @brief Constructor - Lease6(LeaseType type, const isc::asiolink::IOAddress& addr, DuidPtr duid, - uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1, - uint32_t t2, SubnetID subnet_id, uint8_t prefixlen_ = 0); - /// @brief IPv6 address /// /// IPv6 address or, in the case of a prefix delegation, the prefix. @@ -366,10 +362,17 @@ struct Lease6 { /// @todo: Add DHCPv6 failover related fields here + /// @brief Constructor + Lease6(LeaseType type, const isc::asiolink::IOAddress& addr, DuidPtr duid, + uint32_t iaid, uint32_t preferred, uint32_t valid, uint32_t t1, + uint32_t t2, SubnetID subnet_id, uint8_t prefixlen_ = 0); + /// @brief Constructor /// /// Initialize fields that don't have a default constructor. - Lease6() : addr_("::") {} + Lease6() : addr_("::"), type_(LEASE_IA_NA), fixed_(false), fqdn_fwd_(false), + fqdn_rev_(false) + {} /// @brief Convert Lease6 to Printable Form /// diff --git a/src/lib/dhcpsrv/subnet.h b/src/lib/dhcpsrv/subnet.h index aa1ef1fbad..c7d7ac7c73 100644 --- a/src/lib/dhcpsrv/subnet.h +++ b/src/lib/dhcpsrv/subnet.h @@ -172,7 +172,7 @@ public: // Use option type as the index key. The type is held // in OptionPtr object so we have to call Option::getType // to retrieve this key for each element. - boost::multi_index::mem_fun< + boost::multi_index::const_mem_fun< Option, uint16_t, &Option::getType diff --git a/src/lib/dhcpsrv/triplet.h b/src/lib/dhcpsrv/triplet.h index d9388fe5a8..c7b8156061 100644 --- a/src/lib/dhcpsrv/triplet.h +++ b/src/lib/dhcpsrv/triplet.h @@ -37,7 +37,7 @@ public: /// /// Typically: uint32_t to Triplet assignment. It is very convenient /// to be able to simply write Triplet x = 7; - Triplet operator=(T other) { + Triplet& operator=(T other) { min_ = other; default_ = other; max_ = other;