Commit 26be6ac4 authored by Francis Dupont's avatar Francis Dupont
Browse files

[master] Finished merge of trac3919 (cppcheck small fixes)

parents de7a4a80 01c369e5
970. [bug] fdupont
Refactored some code to suppress cppcheck warnings.
(Trac #3919, git xxx)
969. [func] tomek
KEA_SOCKET_TEST_DIR environment variable can be used to specify
the directory for opening Unix sockets during tests. That may
......
......@@ -1611,7 +1611,6 @@ Dhcpv6Srv::assignIA_PD(const Pkt6Ptr& query, const Pkt6Ptr& answer,
// will try to honor the hint, but it is just a hint - some other address
// may be used instead. If fake_allocation is set to false, the lease will
// be inserted into the LeaseMgr as well.
Lease6Collection old_leases;
AllocEngine::ClientContext6 ctx(subnet, duid, ia->getIAID(), hint, Lease::TYPE_PD,
false, false, string(), fake_allocation);
ctx.callout_handle_ = getCalloutHandle(query);
......
......@@ -194,13 +194,10 @@ public:
// Try to obtain the pool parameters. It will throw an exception if any
// of the required parameters are not present or invalid.
std::string addr_str;
uint32_t prefix_len;
uint32_t delegated_len;
try {
addr_str = string_values_->getParam("prefix");
prefix_len = uint32_values_->getParam("prefix-len");
delegated_len = uint32_values_->getParam("delegated-len");
std::string addr_str = string_values_->getParam("prefix");
uint32_t prefix_len = uint32_values_->getParam("prefix-len");
uint32_t delegated_len = uint32_values_->getParam("delegated-len");
// Attempt to construct the local pool.
pool_.reset(new Pool6(Lease::TYPE_PD, IOAddress(addr_str),
......
......@@ -2086,7 +2086,7 @@ TEST_F(Dhcpv6SrvTest, relayOverrideAndClientClass) {
/// @param codes a vector of option codes to be created
/// @param payload specified payload (0 = fill payload with repeating option code)
/// @return RSOO with nested options
OptionPtr createRSOO(const std::vector<uint16_t> codes, uint8_t payload = 0) {
OptionPtr createRSOO(const std::vector<uint16_t>& codes, uint8_t payload = 0) {
OptionDefinitionPtr def = LibDHCP::getOptionDef(Option::V6, D6O_RSOO);
if (!def) {
isc_throw(BadValue, "Can't find RSOO definition");
......
......@@ -389,7 +389,7 @@ public:
const std::string& exp_hostname,
const uint8_t client_flags =
Option6ClientFqdn::FLAG_S,
const IOAddress expected_address = IOAddress("2001:db8:1:1::dead:beef"),
const IOAddress& expected_address = IOAddress("2001:db8:1:1::dead:beef"),
const bool include_oro = true) {
// Create a message of a specified type, add server id and
// FQDN option.
......
......@@ -472,7 +472,6 @@ TEST_F(CommandOptionsTest, Base) {
" -l 127.0.0.1 all"));
std::vector<uint8_t> v1 = opt.getMacTemplate();
std::vector<uint8_t> v2 = opt.getDuidTemplate();
v2 = opt.getDuidTemplate();
EXPECT_TRUE(std::equal(v1.begin(), v1.end(), mac));
EXPECT_TRUE(std::equal(v2.begin(), v2.end(), duid));
// Test valid DUID.
......@@ -786,7 +785,7 @@ TEST_F(CommandOptionsTest, Interface) {
// The local loopback interface should be available.
// If no interface have been found for any reason we should
// not fail this test.
if (ifaces.size() > 0) {
if (!ifaces.empty()) {
// Get the name of the interface we detected.
iface_name = (*ifaces.begin())->getName();
// Use the name in the command parser.
......
......@@ -74,6 +74,7 @@ public:
255, 255, 255, 255, // giaddr
};
// cppcheck-suppress variableScope
uint8_t v4Opts[] = {
DHO_HOST_NAME, 3, 0, 1, 2, // Host name option.
DHO_BOOT_SIZE, 3, 10, 11, 12, // Boot file size option
......
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -269,6 +269,7 @@ class TCPClient : public SimpleClient {
static const unsigned int SERVER_TIME_OUT = 2;
TCPClient(asio::io_service& service, const ip::tcp::endpoint& server)
: SimpleClient(service, SERVER_TIME_OUT),
data_to_send_(""), data_to_send_len_(0),
send_data_delay_(0), send_data_len_delay_(0)
{
server_ = server;
......
......@@ -177,8 +177,11 @@ TEST(UDPSocket, processReceivedData) {
uint8_t inbuff[32]; // Buffer to check
OutputBufferPtr outbuff(new OutputBuffer(16));
// Where data is put
// cppcheck-suppress variableScope
size_t expected; // Expected amount of data
// cppcheck-suppress variableScope
size_t offset; // Where to put next data
// cppcheck-suppress variableScope
size_t cumulative; // Cumulative data received
// Set some dummy values in the buffer to check
......
// Copyright (C) 2009, 2011 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2009, 2011, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -306,10 +306,12 @@ TEST(ModuleSpec, CheckFormat) {
item_default = "";
item_format = "\"item_format\": \"date\"";
specs.push_back("," + item_format);
// cppcheck-suppress redundantAssignment
item_default = "";
item_format = "\"item_format\": \"time\"";
specs.push_back("," + item_format);
// cppcheck-suppress redundantAssignment
item_default = "\"item_default\": \"a\"";
specs.push_back("," + item_default);
item_default = "\"item_default\": \"b\"";
......
// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2014, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -560,8 +560,6 @@ namespace {
}
TEST(HashTest, HashLength) {
std::vector<uint8_t> result;
EXPECT_EQ(8, digestVectorLength(MD5, 8));
EXPECT_EQ(16, digestVectorLength(MD5, 16));
EXPECT_EQ(16, digestVectorLength(MD5, 40));
......
......@@ -638,8 +638,6 @@ namespace {
}
TEST(HMACTest, HMACSigLengthArgument) {
std::vector<uint8_t> sig;
EXPECT_EQ(8, sigVectorLength(MD5, 8));
EXPECT_EQ(16, sigVectorLength(MD5, 16));
EXPECT_EQ(16, sigVectorLength(MD5, 40));
......
......@@ -487,7 +487,6 @@ IfaceMgr::openSockets4(const uint16_t port, const bool use_bcast,
}
}
Iface::AddressCollection addrs = iface->getAddresses();
BOOST_FOREACH(Iface::Address addr, iface->getAddresses()) {
// Skip non-IPv4 addresses and those that weren't selected..
if (!addr.get().isV4() || !addr.isSpecified()) {
......
......@@ -363,7 +363,8 @@ size_t LibDHCP::unpackOptions6(const OptionBuffer& buf,
offset += opt_len;
}
return (offset);
last_offset = offset;
return (last_offset);
}
size_t LibDHCP::unpackOptions4(const OptionBuffer& buf,
......@@ -463,7 +464,8 @@ size_t LibDHCP::unpackOptions4(const OptionBuffer& buf,
options.insert(std::make_pair(opt_type, opt));
offset += opt_len;
}
return (offset);
last_offset = offset;
return (last_offset);
}
size_t LibDHCP::unpackVendorOptions6(const uint32_t vendor_id,
......
......@@ -81,6 +81,9 @@ Pkt4::Pkt4(const uint8_t* data, size_t len)
data_.resize(len);
memcpy(&data_[0], data, len);
memset(sname_, 0, MAX_SNAME_LEN);
memset(file_, 0, MAX_FILE_LEN);
}
size_t
......
......@@ -828,8 +828,7 @@ TEST_F(Pkt6Test, relayPack) {
EXPECT_EQ(opt->len(), optRelay1->len());
OptionBuffer data = opt->getData();
ASSERT_EQ(data.size(), sizeof(relay_opt_data));
EXPECT_EQ(0,
memcmp(relay_opt_data, relay_opt_data, sizeof(relay_opt_data)));
EXPECT_EQ(0, memcmp(&data[0], relay_opt_data, sizeof(relay_opt_data)));
}
......
......@@ -246,7 +246,8 @@ struct Lease4 : public Lease {
/// @brief Default constructor
///
/// Initialize fields that don't have a default constructor.
Lease4() : Lease(0, 0, 0, 0, 0, 0, false, false, "", HWAddrPtr()) {
Lease4() : Lease(0, 0, 0, 0, 0, 0, false, false, "", HWAddrPtr()), ext_(0)
{
}
/// @brief Copy constructor
......
......@@ -308,6 +308,7 @@ public:
/// all variables are initialized/set in the methods before they are used.
MySqlLease4Exchange() : addr4_(0), hwaddr_length_(0), client_id_length_(0),
client_id_null_(MLM_FALSE),
subnet_id_(0), valid_lifetime_(0),
fqdn_fwd_(false), fqdn_rev_(false), hostname_length_(0) {
memset(hwaddr_buffer_, 0, sizeof(hwaddr_buffer_));
memset(client_id_buffer_, 0, sizeof(client_id_buffer_));
......@@ -666,6 +667,8 @@ public:
/// The initialization of the variables here is nonly to satisfy cppcheck -
/// all variables are initialized/set in the methods before they are used.
MySqlLease6Exchange() : addr6_length_(0), duid_length_(0),
iaid_(0), lease_(0), lease_type_(0), prefixlen_(0),
pref_lifetime_(0), subnet_id_(0), valid_lifetime_(0),
fqdn_fwd_(false), fqdn_rev_(false),
hostname_length_(0), hwaddr_length_(0),
hwaddr_null_(MLM_FALSE), hwtype_(0), hwaddr_source_(0) {
......
......@@ -670,7 +670,7 @@ MasterLoader::MasterLoaderImpl::generateForIter(const std::string& str,
int offset = 0;
unsigned int width;
char base[2] = {'d', 0}; // char plus null byte
// cppcheck-suppress invalidscanf
// cppcheck-suppress invalidscanf_libc
const int n = sscanf(scan_str, "{%d,%u,%1[doxXnN]}",
&offset, &width, base);
switch (n) {
......@@ -807,7 +807,7 @@ MasterLoader::MasterLoaderImpl::doGenerate() {
unsigned int start;
unsigned int stop;
unsigned int step;
// cppcheck-suppress invalidscanf
// cppcheck-suppress invalidscanf_libc
const int n = sscanf(range.c_str(), "%u-%u/%u", &start, &stop, &step);
if ((n < 2) || (stop < start)) {
reportError(lexer_.getSourceName(), lexer_.getSourceLine(),
......
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011, 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
......@@ -34,7 +34,7 @@ using namespace isc::dns;
class NAPTRImpl {
public:
NAPTRImpl() : replacement(".") {}
NAPTRImpl() : order(0), preference(0), replacement(".") {}
NAPTRImpl(InputBuffer& buffer, size_t rdata_len) : replacement(".") {
if (rdata_len < 4 || buffer.getLength() - buffer.getPosition() < 4) {
......
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