Commit 139c1d30 authored by Francis Dupont's avatar Francis Dupont
Browse files

[master] Merged trac4326 (small Coverity fixes)

parents 035843d3 b9a4336d
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
[<!ENTITY mdash "&#8212;">]>
[<!ENTITY mdash "&#8212;">]>
<!--
- Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
-
......
// Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2013-2016 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
......@@ -215,7 +215,8 @@ public:
std::vector<NameChangeRequestPtr> received_ncrs_;
QueueMgrUDPTest() : io_service_(new isc::asiolink::IOService()),
test_timer_(*io_service_) {
test_timer_(*io_service_),
send_result_(NameChangeSender::SUCCESS) {
isc::asiolink::IOAddress addr(TEST_ADDRESS);
// Create our sender instance. Note that reuse_address is true.
sender_.reset(new NameChangeUDPSender(addr, SENDER_PORT,
......
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
[<!ENTITY mdash "&#8212;">]>
[<!ENTITY mdash "&#8212;">]>
<!--
- Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
-
......
......@@ -958,7 +958,7 @@ status_no_config_test() {
assert_string_contains "DHCP DDNS: inactive" "${output}" \
"Expected keactrl status command return %s"
assert_string_contains "Configuration file for Kea does not exist" \
"${output}" "Expected keactrl status command return %s"
"${output}" "Expected keactrl status command return %s"
test_finish 0
}
......
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
[<!ENTITY mdash "&#8212;">]>
[<!ENTITY mdash "&#8212;">]>
<!--
- Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
-
......
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
[<!ENTITY mdash "&#8212;">]>
[<!ENTITY mdash "&#8212;">]>
<!--
- Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
-
......@@ -81,6 +81,3 @@
- mode: sgml
- End:
-->
......@@ -455,13 +455,13 @@ TEST(TCPSocket, sequenceTest) {
}
}
// Has the client run?
// Has the client run?
if (!client_complete) {
if (client_cb.called() != client_cb.queued()) {
// No. Run the service another time.
continue;
}
if (client_cb.called() != client_cb.queued()) {
// No. Run the service another time.
continue;
}
// Client callback must have run. Check that it ran OK.
EXPECT_EQ(TCPCallback::READ, client_cb.called());
......
{
"zones": [
{
"example.org": {
"queries.tcp": 100,
"queries.udp": 200
}
},
{
"example.net": {
"queries.tcp": 300,
"queries.udp": 400
}
{
"example.org": {
"queries.tcp": 100,
"queries.udp": 200
}
},
{
"example.net": {
"queries.tcp": 300,
"queries.udp": 400
}
}
]
}
// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011-2016 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
......@@ -883,7 +883,7 @@ TEST_F(IfaceMgrTest, multipleSockets) {
init_sockets_it != init_sockets.end(); ++init_sockets_it) {
// recv() must result in error when using invalid socket.
char buf;
recv(*init_sockets_it, &buf, 1, MSG_PEEK);
static_cast<void>(recv(*init_sockets_it, &buf, 1, MSG_PEEK));
// EWOULDBLOCK would mean that socket is valid/open but
// simply no data is received so we have to check for
// other errors.
......
// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2016 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
......@@ -362,6 +362,7 @@ TEST_F(OptionDefinitionTest, ipv6AddressArray) {
option_v6 = opt_def.optionFactory(Option::V6, D6O_NIS_SERVERS, buf);
);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(Option6AddrLst));
boost::shared_ptr<Option6AddrLst> option_cast_v6 =
boost::static_pointer_cast<Option6AddrLst>(option_v6);
......@@ -418,6 +419,7 @@ TEST_F(OptionDefinitionTest, ipv6AddressArrayTokenized) {
// should have Option6AddrLst type.
ASSERT_TRUE(option_v6);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(Option6AddrLst));
// Cast to the actual option type to get IPv6 addresses from it.
boost::shared_ptr<Option6AddrLst> option_cast_v6 =
......@@ -462,6 +464,7 @@ TEST_F(OptionDefinitionTest, ipv4AddressArray) {
option_v4 = opt_def.optionFactory(Option::V4, DHO_NAME_SERVERS, buf)
);
const Option* optptr = option_v4.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(Option4AddrLst));
// Get the list of parsed addresses from the option object.
boost::shared_ptr<Option4AddrLst> option_cast_v4 =
......@@ -515,6 +518,7 @@ TEST_F(OptionDefinitionTest, ipv4AddressArrayTokenized) {
// should have Option6AddrLst type.
ASSERT_TRUE(option_v4);
const Option* optptr = option_v4.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(Option4AddrLst));
// Cast to the actual option type to get IPv4 addresses from it.
boost::shared_ptr<Option4AddrLst> option_cast_v4 =
......@@ -540,6 +544,7 @@ TEST_F(OptionDefinitionTest, empty) {
option_v6 = opt_def.optionFactory(Option::V6, D6O_RAPID_COMMIT, OptionBuffer())
);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(Option));
// Expect 'empty' DHCPv6 option.
EXPECT_EQ(Option::V6, option_v6->getUniverse());
......@@ -584,6 +589,7 @@ TEST_F(OptionDefinitionTest, emptyWithSuboptions) {
);
// Returned option should be of the OptionCustom type.
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionCustom));
// Sanity-check length, universe etc.
EXPECT_EQ(Option::V6, option_v6->getUniverse());
......@@ -623,6 +629,7 @@ TEST_F(OptionDefinitionTest, binary) {
);
// Expect base option type returned.
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(Option));
// Sanity check on universe, length and size. These are
// the basic parameters identifying any option.
......@@ -671,6 +678,7 @@ TEST_F(OptionDefinitionTest, recordIA6) {
OptionPtr option_v6;
ASSERT_NO_THROW(option_v6 = opt_def.optionFactory(Option::V6, D6O_IA_NA, buf));
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(Option6IA));
boost::shared_ptr<Option6IA> option_cast_v6 =
boost::static_pointer_cast<Option6IA>(option_v6);
......@@ -715,6 +723,7 @@ TEST_F(OptionDefinitionTest, recordIAAddr6) {
}
ASSERT_NO_THROW(option_v6 = opt_def.optionFactory(Option::V6, D6O_IAADDR, buf));
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(Option6IAAddr));
boost::shared_ptr<Option6IAAddr> option_cast_v6 =
boost::static_pointer_cast<Option6IAAddr>(option_v6);
......@@ -753,6 +762,7 @@ TEST_F(OptionDefinitionTest, recordIAAddr6Tokenized) {
ASSERT_NO_THROW(option_v6 = opt_def.optionFactory(Option::V6, D6O_IAADDR,
data_field_values));
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(Option6IAAddr));
boost::shared_ptr<Option6IAAddr> option_cast_v6 =
boost::static_pointer_cast<Option6IAAddr>(option_v6);
......@@ -776,6 +786,7 @@ TEST_F(OptionDefinitionTest, boolValue) {
OptionBuffer(1, 1));
);
const Option* optptr = option_v4.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionCustom));
// Validate parsed value in the received option.
boost::shared_ptr<OptionCustom> option_cast_v4 =
......@@ -816,6 +827,7 @@ TEST_F(OptionDefinitionTest, boolTokenized) {
values);
);
const Option* optptr = option_v4.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionCustom));
// Validate the value.
OptionCustomPtr option_cast_v4 =
......@@ -829,6 +841,7 @@ TEST_F(OptionDefinitionTest, boolTokenized) {
values);
);
optptr = option_v4.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionCustom));
// Validate the value.
option_cast_v4 = boost::static_pointer_cast<OptionCustom>(option_v4);
......@@ -841,6 +854,7 @@ TEST_F(OptionDefinitionTest, boolTokenized) {
values);
);
optptr = option_v4.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionCustom));
// Validate the value.
option_cast_v4 = boost::static_pointer_cast<OptionCustom>(option_v4);
......@@ -853,6 +867,7 @@ TEST_F(OptionDefinitionTest, boolTokenized) {
values);
);
optptr = option_v4.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionCustom));
// Validate the value.
option_cast_v4 = boost::static_pointer_cast<OptionCustom>(option_v4);
......@@ -885,6 +900,7 @@ TEST_F(OptionDefinitionTest, uint8) {
OptionBuffer(1, 1));
);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionInt<uint8_t>));
// Validate the value.
boost::shared_ptr<OptionInt<uint8_t> > option_cast_v6 =
......@@ -914,6 +930,7 @@ TEST_F(OptionDefinitionTest, uint8Tokenized) {
option_v6 = opt_def.optionFactory(Option::V6, D6O_PREFERENCE, values);
);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionInt<uint8_t>));
// Validate the value.
boost::shared_ptr<OptionInt<uint8_t> > option_cast_v6 =
......@@ -938,6 +955,7 @@ TEST_F(OptionDefinitionTest, uint16) {
option_v6 = opt_def.optionFactory(Option::V6, D6O_ELAPSED_TIME, buf);
);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionInt<uint16_t>));
// Validate the value.
boost::shared_ptr<OptionInt<uint16_t> > option_cast_v6 =
......@@ -968,6 +986,7 @@ TEST_F(OptionDefinitionTest, uint16Tokenized) {
option_v6 = opt_def.optionFactory(Option::V6, D6O_ELAPSED_TIME, values);
);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionInt<uint16_t>));
// Validate the value.
boost::shared_ptr<OptionInt<uint16_t> > option_cast_v6 =
......@@ -994,6 +1013,7 @@ TEST_F(OptionDefinitionTest, uint32) {
option_v6 = opt_def.optionFactory(Option::V6, D6O_CLT_TIME, buf);
);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionInt<uint32_t>));
// Validate the value.
boost::shared_ptr<OptionInt<uint32_t> > option_cast_v6 =
......@@ -1023,6 +1043,7 @@ TEST_F(OptionDefinitionTest, uint32Tokenized) {
option_v6 = opt_def.optionFactory(Option::V6, D6O_CLT_TIME, values);
);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionInt<uint32_t>));
// Validate the value.
boost::shared_ptr<OptionInt<uint32_t> > option_cast_v6 =
......@@ -1053,6 +1074,7 @@ TEST_F(OptionDefinitionTest, uint16Array) {
option_v6 = opt_def.optionFactory(Option::V6, opt_code, buf);
);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionIntArray<uint16_t>));
boost::shared_ptr<OptionIntArray<uint16_t> > option_cast_v6 =
boost::static_pointer_cast<OptionIntArray<uint16_t> >(option_v6);
......@@ -1096,6 +1118,7 @@ TEST_F(OptionDefinitionTest, uint16ArrayTokenized) {
option_v6 = opt_def.optionFactory(Option::V6, opt_code, str_values);
);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionIntArray<uint16_t>));
boost::shared_ptr<OptionIntArray<uint16_t> > option_cast_v6 =
boost::static_pointer_cast<OptionIntArray<uint16_t> >(option_v6);
......@@ -1128,6 +1151,7 @@ TEST_F(OptionDefinitionTest, uint32Array) {
option_v6 = opt_def.optionFactory(Option::V6, opt_code, buf);
);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionIntArray<uint32_t>));
boost::shared_ptr<OptionIntArray<uint32_t> > option_cast_v6 =
boost::static_pointer_cast<OptionIntArray<uint32_t> >(option_v6);
......@@ -1174,6 +1198,7 @@ TEST_F(OptionDefinitionTest, uint32ArrayTokenized) {
option_v6 = opt_def.optionFactory(Option::V6, opt_code, str_values);
);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionIntArray<uint32_t>));
boost::shared_ptr<OptionIntArray<uint32_t> > option_cast_v6 =
boost::static_pointer_cast<OptionIntArray<uint32_t> >(option_v6);
......@@ -1201,6 +1226,7 @@ TEST_F(OptionDefinitionTest, utf8StringTokenized) {
);
ASSERT_TRUE(option_v6);
const Option* optptr = option_v6.get();
ASSERT_TRUE(optptr);
ASSERT_TRUE(typeid(*optptr) == typeid(OptionString));
OptionStringPtr option_v6_string =
boost::static_pointer_cast<OptionString>(option_v6);
......
......@@ -503,18 +503,18 @@ public:
}
private:
uint32_t host_id_; /// Host unique identifier
uint32_t host_id_; /// Host unique identifier
std::vector<uint8_t> dhcp_identifier_; /// HW address (0) / DUID (1)
uint8_t dhcp_identifier_buffer_[DUID::MAX_DUID_LEN];
/// Buffer for dhcp identifier
unsigned long dhcp_identifier_length_; /// Length of dhcp identifier
uint8_t dhcp_identifier_type_; /// Type of dhcp_identifier
uint32_t dhcp4_subnet_id_; /// Subnet DHCPv4 identifier
uint32_t dhcp6_subnet_id_; /// Subnet DHCPv6 identifier
uint32_t ipv4_address_; /// Reserved IPv4 address.
IPv6ResrvCollection ipv6_reservations_; /// IPv6 reservations collection
uint8_t dhcp_identifier_type_; /// Type of dhcp_identifier
uint32_t dhcp4_subnet_id_; /// Subnet DHCPv4 identifier
uint32_t dhcp6_subnet_id_; /// Subnet DHCPv6 identifier
uint32_t ipv4_address_; /// Reserved IPv4 address.
IPv6ResrvCollection ipv6_reservations_; /// IPv6 reservations collection
char hostname_[HOSTNAME_MAX_LEN]; /// Name reserved for the host
unsigned long hostname_length_; /// hostname length
unsigned long hostname_length_; /// hostname length
char dhcp4_client_classes_[CLIENT_CLASSES_MAX_LEN];
/// DHCPv4 client classes
unsigned long dhcp4_client_classes_length_; /// dhcp4_client_classes length
......@@ -522,7 +522,7 @@ private:
/// DHCPv6 client classes
unsigned long dhcp6_client_classes_length_; /// dhcp6_client_classes length
HWAddrPtr hw_address_; /// Pointer to hardware address
DuidPtr duid_; /// Pointer to DUID
DuidPtr duid_; /// Pointer to DUID
// NULL flags for subnets id, ipv4 address, hostname and client classes
my_bool dhcp4_subnet_id_null_;
......@@ -533,9 +533,9 @@ private:
my_bool dhcp6_client_classes_null_;
MYSQL_BIND bind_[HOST_COLUMNS];
std::string columns_[HOST_COLUMNS]; /// Column names
std::string columns_[HOST_COLUMNS]; /// Column names
my_bool error_[HOST_COLUMNS]; /// Error array
HostPtr host_; // Pointer to Host object
HostPtr host_; // Pointer to Host object
};
// MySqlHostDataSource Constructor and Destructor
......
......@@ -221,13 +221,13 @@ public:
///
/// The contents of the enum are indexes into the list of SQL statements
enum StatementIndex {
INSERT_HOST, // Insert new host to collection
INSERT_HOST, // Insert new host to collection
GET_HOST_HWADDR_DUID, // Gets hosts by DUID and/or HW address
GET_HOST_ADDR, // Gets hosts by IPv4 address
GET_HOST_SUBID4_DHCPID, // Gets host by IPv4 SubnetID, HW address/DUID
GET_HOST_SUBID6_DHCPID, // Gets host by IPv6 SubnetID, HW address/DUID
GET_HOST_ADDR, // Gets hosts by IPv4 address
GET_HOST_SUBID4_DHCPID, // Gets host by IPv4 SubnetID, HW address/DUID
GET_HOST_SUBID6_DHCPID, // Gets host by IPv6 SubnetID, HW address/DUID
GET_HOST_SUBID_ADDR, // Gets host by IPv4 SubnetID and IPv4 address
GET_HOST_PREFIX, // Gets host by IPv6 prefix
GET_HOST_PREFIX, // Gets host by IPv6 prefix
GET_VERSION, // Obtain version number
NUM_STATEMENTS // Number of statements
};
......@@ -236,7 +236,7 @@ private:
/// @brief Add Host Code
///
/// This method performs adding a host operation.
/// It binds the contents of the host object to
/// It binds the contents of the host object to
/// the prepared statement and adds it to the database.
///
/// @param stindex Index of statemnent being executed
......
// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2015-2016 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
......@@ -1854,7 +1854,7 @@ void
ExpirationAllocEngine4Test::setUniqueClientId(const uint16_t index) {
std::ostringstream clientid_s;
clientid_s << "AA:BB:" << std::setw(2) << std::setfill('0')
<< (index >> 16) << ":" << std::setw(2) << std::setfill('0')
<< (index >> 8) << ":" << std::setw(2) << std::setfill('0')
<< (index & 0x00FF);
ClientIdPtr client_id(ClientId::fromText(clientid_s.str()));
leases_[index]->client_id_ = client_id;
......
......@@ -43,7 +43,7 @@ Opcode::Opcode(const uint8_t code) : code_(static_cast<CodeValue>(code)) {
if (code > MAX_OPCODE) {
isc_throw(OutOfRange,
"DNS Opcode is too large to construct: "
<< static_cast<unsigned>(code));
<< static_cast<unsigned>(code));
}
}
......
......@@ -34,6 +34,8 @@ public:
EvaluateTest() {
e_.clear();
result_ = false;
pkt4_.reset(new Pkt4(DHCPDISCOVER, 12345));
pkt6_.reset(new Pkt6(DHCPV6_SOLICIT, 12345));
......
......@@ -31,7 +31,7 @@ TEST(BoostTimeUtilsTest, epoch) {
// The 2015 Bastille day
TEST(BoostTimeUtilsTest, bastilleDay) {
time_duration tdbast =
hours(12) + minutes(13) + seconds(14) + milliseconds(500);
hours(12) + minutes(13) + seconds(14) + milliseconds(500);
ptime pbast(date(2015, Jul, 14), tdbast);
string sbast = ptimeToText(pbast);
EXPECT_EQ("2015-07-14 12:13:14.500", sbast.substr(0, 23));
......
// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011-2016 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
......@@ -474,7 +474,7 @@ ForwardTest::checkPushAndPop(int family, int type, int protocol,
false));
setNonBlock(client_sock.fd, true);
// This connect would "fail" due to EINPROGRESS. Ignore it for now.
connect(client_sock.fd, local.first, local.second);
static_cast<void>(connect(client_sock.fd, local.first, local.second));
sockaddr_storage ss;
socklen_t salen = sizeof(ss);
server_sock.reset(accept(sock.fd, convertSockAddr(&ss), &salen));
......
// Copyright (C) 2012-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2012-2016 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
......@@ -66,7 +66,8 @@ public:
// and the creating thread needs to release it.
waiting_(2),
main_(main),
exception_(false)
exception_(false),
tid_(0)
{}
// Another of the waiting events is done. If there are no more, delete
// impl.
......
// Copyright (C) 2010-2015 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2010-2016 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
......@@ -135,8 +135,10 @@ timeToText32(const uint32_t value) {
namespace {
const size_t DATE_LEN = 14; // YYYYMMDDHHmmSS
inline uint64_t ull(const int c) { return (static_cast<uint64_t>(c)); }
inline void
checkRange(const int min, const int max, const int value,
checkRange(const unsigned min, const unsigned max, const unsigned value,
const string& valname)
{
if ((value >= min) && (value <= max)) {
......@@ -157,9 +159,9 @@ timeFromText64(const string& time_txt) {
}
}
int year, month, day, hour, minute, second;
unsigned year, month, day, hour, minute, second;
if (time_txt.length() != DATE_LEN ||
sscanf(time_txt.c_str(), "%4d%2d%2d%2d%2d%2d",
sscanf(time_txt.c_str(), "%4u%2u%2u%2u%2u%2u",
&year, &month, &day, &hour, &minute, &second) != 6)
{
isc_throw(InvalidTime, "Couldn't convert time value: " << time_txt);
......@@ -173,16 +175,16 @@ timeFromText64(const string& time_txt) {
checkRange(0, 59, minute, "minute");
checkRange(0, 60, second, "second"); // 60 == leap second.
uint64_t timeval = second + (60 * minute) + (3600 * hour) +
((day - 1) * 86400);
for (int m = 0; m < (month - 1); ++m) {
timeval += days[m] * 86400;
uint64_t timeval = second + (ull(60) * minute) + (ull(3600) * hour) +
((day - 1) * ull(86400));
for (unsigned m = 0; m < (month - 1); ++m) {
timeval += days[m] * ull(86400);
}
if (isLeap(year) && month > 2) {
timeval += 86400;
timeval += ull(86400);
}
for (int y = 1970; y < year; ++y) {
timeval += ((isLeap(y) ? 366 : 365 ) * 86400);
for (unsigned y = 1970; y < year; ++y) {
timeval += ((isLeap(y) ? 366 : 365) * ull(86400));
}
return (timeval);
......
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