Commit e4e8de31 authored by Stephen Morris's avatar Stephen Morris

[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.
parent 03b92733
......@@ -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)
......
......@@ -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.
///
......
......@@ -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();
......
......@@ -209,7 +209,7 @@ OptionDataTypeUtil::writeBool(const bool value,
std::string
OptionDataTypeUtil::readString(const std::vector<uint8_t>& buf) {
std::string value;
if (buf.size() > 0) {
if (!buf.empty()) {
value.insert(value.end(), buf.begin(), buf.end());
}
return (value);
......
......@@ -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);
......
......@@ -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");
}
......
......@@ -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.
///
......
......@@ -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.
///
......
......@@ -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
///
......
......@@ -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
......
......@@ -37,7 +37,7 @@ public:
///
/// Typically: uint32_t to Triplet assignment. It is very convenient
/// to be able to simply write Triplet<uint32_t> x = 7;
Triplet<T> operator=(T other) {
Triplet<T>& operator=(T other) {
min_ = other;
default_ = other;
max_ = other;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment