-// Copyright (C) 2013-2015,2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2020 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
// If the Zone counter is greater than 0 (which we have checked)
// there must be a valid Question pointer stored in the message_
// object. If there isn't, it is a programming error.
- assert(question);
+ if (!question) {
+ isc_throw(isc::Unexpected, "question is null?!");
+ }
zone_.reset(new D2Zone(question->getName(), question->getClass()));
} else {
} // namespace d2
} // namespace isc
-
void IOFetch::logIOFailure(boost::system::error_code ec) {
// Should only get here with a known error code.
- assert((data_->origin == ASIODNS_OPEN_SOCKET) ||
- (data_->origin == ASIODNS_SEND_DATA) ||
- (data_->origin == ASIODNS_READ_DATA) ||
- (data_->origin == ASIODNS_UNKNOWN_ORIGIN));
+ if ((data_->origin != ASIODNS_OPEN_SOCKET) &&
+ (data_->origin != ASIODNS_SEND_DATA) &&
+ (data_->origin != ASIODNS_READ_DATA) &&
+ (data_->origin != ASIODNS_UNKNOWN_ORIGIN)) {
+ isc_throw(isc::Unexpected, "impossible error code " << data_->origin);
+ }
LOG_ERROR(logger, data_->origin).arg(ec.value()).
arg((data_->remote_snd->getProtocol() == IPPROTO_TCP) ?
#include <unistd.h> // for some IPC/network system calls
#include <algorithm>
-#include <cassert>
#include <cstddef>
#include <boost/numeric/conversion/cast.hpp>
#include <asiolink/io_service.h>
#include <asiolink/tcp_endpoint.h>
+#include <exceptions/isc_assert.h>
+
namespace isc {
namespace asiolink {
// IOEndpoint is the base class of UDPEndpoint and TCPEndpoint, it does not
// contain a method for getting at the underlying endpoint type - that is in
/// the derived class and the two classes differ on return type.
- assert(endpoint->getProtocol() == IPPROTO_TCP);
+ isc_throw_assert(endpoint->getProtocol() == IPPROTO_TCP);
const TCPEndpoint* tcp_endpoint =
static_cast<const TCPEndpoint*>(endpoint);
// does not contain a method for getting at the underlying endpoint
// type - that is in the derived class and the two classes differ on
// return type.
- assert(endpoint->getProtocol() == IPPROTO_TCP);
+ isc_throw_assert(endpoint->getProtocol() == IPPROTO_TCP);
TCPEndpoint* tcp_endpoint = static_cast<TCPEndpoint*>(endpoint);
// Write the endpoint details from the communications link. Ideally
-// Copyright (C) 2011-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2020 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
#include <asiolink/io_service.h>
#include <asiolink/udp_endpoint.h>
+#include <exceptions/isc_assert.h>
+
namespace isc {
namespace asiolink {
// does not contain a method for getting at the underlying endpoint
// type - that is in the derived class and the two classes differ on
// return type.
- assert(endpoint->getProtocol() == IPPROTO_UDP);
+ isc_throw_assert(endpoint->getProtocol() == IPPROTO_UDP);
const UDPEndpoint* udp_endpoint =
static_cast<const UDPEndpoint*>(endpoint);
if (isopen_) {
// Upconvert the endpoint again.
- assert(endpoint->getProtocol() == IPPROTO_UDP);
+ isc_throw_assert(endpoint->getProtocol() == IPPROTO_UDP);
UDPEndpoint* udp_endpoint = static_cast<UDPEndpoint*>(endpoint);
// Ensure we can write into the buffer
#include <dhcp/std_option_defs.h>
#include <dhcp/docsis3_option_defs.h>
#include <exceptions/exceptions.h>
+#include <exceptions/isc_assert.h>
#include <util/buffer.h>
#include <boost/lexical_cast.hpp>
// The option definition has been found. Use it to create
// the option instance from the provided buffer chunk.
const OptionDefinitionPtr& def = *(range.first);
- assert(def);
+ isc_throw_assert(def);
opt = def->optionFactory(Option::V6, opt_type,
buf.begin() + offset,
buf.begin() + offset + opt_len);
// The option definition has been found. Use it to create
// the option instance from the provided buffer chunk.
const OptionDefinitionPtr& def = *(range.first);
- assert(def);
+ isc_throw_assert(def);
opt = def->optionFactory(Option::V4, opt_type,
buf.begin() + offset,
buf.begin() + offset + opt_len);
// The option definition has been found. Use it to create
// the option instance from the provided buffer chunk.
const OptionDefinitionPtr& def = *(range.first);
- assert(def);
+ isc_throw_assert(def);
opt = def->optionFactory(Option::V6, opt_type,
buf.begin() + offset,
buf.begin() + offset + opt_len);
// The option definition has been found. Use it to create
// the option instance from the provided buffer chunk.
const OptionDefinitionPtr& def = *(range.first);
- assert(def);
+ isc_throw_assert(def);
opt = def->optionFactory(Option::V4, opt_type,
buf.begin() + offset,
buf.begin() + offset + opt_len);
-// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2020 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
#include <dhcp/libdhcp++.h>
#include <dhcp/option_data_types.h>
#include <dhcp/option_custom.h>
+#include <exceptions/isc_assert.h>
#include <util/encode/hex.h>
using namespace isc::asiolink;
// Code copied from the standard array case
size_t data_size = bufferLength(fields.back(), true,
data, data_buf.end());
- assert(data_size > 0);
+ isc_throw_assert(data_size > 0);
if (std::distance(data, data_buf.end()) < data_size) {
break;
}
// etc. This is because OptionDefinition::validate function should
// have checked this already. Thus data_size must be greater than
// zero.
- assert(data_size > 0);
+ isc_throw_assert(data_size > 0);
// Get chunks of data and store as a collection of buffers.
// Truncate any remaining part which length is not divisible by
// data_size. Note that it is ok to truncate the data if and only
-// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2020 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
#include <asiolink/io_address.h>
#include <dhcp/option.h>
#include <dhcp/option_definition.h>
+#include <exceptions/isc_assert.h>
#include <util/io_utilities.h>
namespace isc {
checkDataType<T>(index);
// When we created the buffer we have checked that it has a
// valid size so this condition here should be always fulfilled.
- assert(buffers_[index].size() == OptionDataTypeTraits<T>::len);
+ isc_throw_assert(buffers_[index].size() == OptionDataTypeTraits<T>::len);
// Read an integer value.
return (OptionDataTypeUtil::readInt<T>(buffers_[index]));
}
// When we initialized buffers we have already checked that
// the number of these buffers is equal to number of option
// fields in the record so the condition below should be met.
- assert(index < record_fields.size());
+ isc_throw_assert(index < record_fields.size());
// Get the data type to be returned.
data_type = record_fields[index];
}
#include <dhcp/iface_mgr.h>
#include <dhcp/pkt6.h>
#include <dhcp/pkt_filter_inet6.h>
+#include <exceptions/isc_assert.h>
#include <util/io/pktinfo_utilities.h>
#include <fcntl.h>
// CMSG_FIRSTHDR() is coded to return NULL as a possibility. The
// following assertion should never fail, but if it did and you came
// here, fix the code. :)
- assert(cmsg != NULL);
+ isc_throw_assert(cmsg != NULL);
cmsg->cmsg_level = IPPROTO_IPV6;
cmsg->cmsg_type = IPV6_PKTINFO;
-// Copyright (C) 2011-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2020 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
#include <log/logger_specification.h>
#include <log/buffer_appender_impl.h>
+#include <exceptions/isc_assert.h>
+
#include <boost/lexical_cast.hpp>
using namespace std;
for (it = copy.begin(); it != copy.end(); ++it) {
internal::BufferAppender* app =
dynamic_cast<internal::BufferAppender*>(it->get());
- assert(app != NULL);
+ isc_throw_assert(app);
app->flush();
}
}
-// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2020 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
#include <config.h>
-#include <cassert>
#include <errno.h>
#include <string.h>
#include <iostream>
#include <iostream>
#include <fstream>
+#include <exceptions/isc_assert.h>
#include <log/log_messages.h>
#include <log/message_exception.h>
#include <log/message_reader.h>
MessageReader::parsePrefix(const vector<string>& tokens) {
// Should not get here unless there is something in the tokens array.
- assert(!tokens.empty());
+ isc_throw_assert(!tokens.empty());
// Process $PREFIX. With no arguments, the prefix is set to the empty
// string. One argument sets the prefix to the to its value and more than
// The line passed should be at least one character long and start with the
// message introducer (else we should not have got here).
- assert((text.size() >= 1) && (text[0] == MESSAGE_FLAG));
+ isc_throw_assert((text.size() >= 1) && (text[0] == MESSAGE_FLAG));
// A line comprising just the message introducer is not valid.
if (text.size() == 1) {
-// Copyright (C) 2009-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2009-2020 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
///
/// \param pos The position in the buffer to be returned.
uint8_t operator[](size_t pos) const {
- assert (pos < size_);
+ if (pos >= size_) {
+ isc_throw(InvalidBufferPosition,
+ "[]: pos (" << pos << ") >= size (" << size_ << ")");
+ }
return (buffer_[pos]);
}
//@}
// See http://www.boost.org for updates, documentation, and revision history.
-#include <cassert>
+#include <exceptions/isc_assert.h>
#include <cstddef> // size_t
#include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
const char * lookup_table =
"0123456789"
"ABCDEF";
- assert(t < 16);
+ isc_throw_assert(t < 16);
return (lookup_table[static_cast<size_t>(t)]);
}
};
// See http://www.boost.org for updates, documentation, and revision history.
-#include <cassert>
+#include <exceptions/isc_assert.h>
#include <cstddef> // size_t
#include <boost/config.hpp> // for BOOST_DEDUCED_TYPENAME
const char * lookup_table =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUV";
- assert(t < 32);
+ isc_throw_assert(t < 32);
return (lookup_table[static_cast<size_t>(t)]);
}
};
-// Copyright (C) 2010-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2010-2020 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
#include <util/encode/base64.h>
#include <exceptions/exceptions.h>
+#include <exceptions/isc_assert.h>
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <stdint.h>
#include <stdexcept>
-#include <cassert>
#include <iterator>
#include <string>
#include <vector>
result.reserve(len);
result.assign(Encoder(EncodeNormalizer(binary.begin(), binary.end())),
Encoder(EncodeNormalizer(binary.end(), binary.end())));
- assert(len >= result.length());
+ isc_throw_assert(len >= result.length());
result.append(len - result.length(), BASE_PADDING_CHAR);
return (result);
}
// data, that is, that the first byte of padding is indeed 0.
// (DecodeNormalizer and binary_from_baseXX ensure that the rest of the
// padding is all zero).
- assert(result.size() >= padbytes);
+ isc_throw_assert(result.size() >= padbytes);
if (padbytes > 0 && *(result.end() - padbytes) != 0) {
isc_throw(BadValue, "Non 0 bits included in " << algorithm
<< " padding: " << input);
-// Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2020 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
#include <sys/socket.h>
#include <netinet/in.h>
-#include <cassert>
+#include <exceptions/isc_assert.h>
// These definitions in this file are for the convenience of internal
// implementation and test code, and are not intended to be used publicly.
if (sa.sa_family == AF_INET) {
return (sizeof(struct sockaddr_in));
} else {
- assert(sa.sa_family == AF_INET6);
+ isc_throw_assert(sa.sa_family == AF_INET6);
return (sizeof(struct sockaddr_in6));
}
}
-// Copyright (C) 2011-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2011-2020 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
#include <csignal>
#include <cstddef>
#include <cstring>
-#include <cassert>
#include <string>
#include <vector>
#include <boost/noncopyable.hpp>
#include <exceptions/exceptions.h>
+#include <exceptions/isc_assert.h>
#include <util/buffer.h>
memset(&impl.sock_un_.sun_path, 0, sizeof(impl.sock_un_.sun_path));
strncpy(impl.sock_un_.sun_path, unix_file.c_str(),
sizeof(impl.sock_un_.sun_path) - 1);
- assert(impl.sock_un_.sun_path[sizeof(impl.sock_un_.sun_path) - 1] == '\0');
+ isc_throw_assert(impl.sock_un_.sun_path[sizeof(impl.sock_un_.sun_path) - 1] == '\0');
impl.sock_un_len_ = offsetof(struct sockaddr_un, sun_path) +
unix_file.length();
#ifdef HAVE_SA_LEN
impl_->buf_.writeData(&remote_end, getSALength(remote_end));
// Data length. Must be fit uint32 due to the range check above.
const uint32_t data_len32 = static_cast<uint32_t>(data_len);
- assert(data_len == data_len32); // shouldn't cause overflow.
+ isc_throw_assert(data_len == data_len32); // shouldn't cause overflow.
impl_->buf_.writeUint32(data_len32);
// Write the resulting header length at the beginning of the buffer
impl_->buf_.writeUint16At(impl_->buf_.getLength() - sizeof(uint16_t), 0);
-// Copyright (C) 2010-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2010-2020 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
public:
/// \brief Constructor
///
- /// \param probabilities The probabilities for all the integers, the probability must be
+ /// \param probabilities The probabilities for all the integers, the probability must be
/// between 0 and 1.0, the sum of probabilities must be equal to 1.
/// For example, if the probabilities contains the following values:
/// 0.5 0.3 0.2, the 1st integer will be generated more frequently than the
/// other integers and the probability is proportional to its value.
- /// \param min The minimum integer that generated, other integers will be
+ /// \param min The minimum integer that generated, other integers will be
/// min, min + 1, ..., min + probabilities.size() - 1
WeightedRandomIntegerGenerator(const std::vector<double>& probabilities,
size_t min = 0):
{
// The probabilities must be valid. Checking is quite an expensive
// operation, so is only done in a debug build.
- assert(areProbabilitiesValid(probabilities));
+ areProbabilitiesValid(probabilities);
// Calculate the partial sum of probabilities
std::partial_sum(probabilities.begin(), probabilities.end(),
void reset(const std::vector<double>& probabilities, size_t min = 0)
{
// The probabilities must be valid.
- assert(areProbabilitiesValid(probabilities));
+ areProbabilitiesValid(probabilities);
// Reset the cumulative sum
cumulative_.clear();
/// \brief Generate weighted random integer
size_t operator()()
{
- return std::lower_bound(cumulative_.begin(), cumulative_.end(), uniform_real_gen_())
+ return std::lower_bound(cumulative_.begin(), cumulative_.end(), uniform_real_gen_())
- cumulative_.begin() + min_;
}
/// error, an exception is thrown. This makes unit testing somewhat easier.
///
/// \param probabilities Vector of probabilities.
- bool areProbabilitiesValid(const std::vector<double>& probabilities) const
+ /// \throw InvalidProbValue or SumNotOne when not valid.
+ void areProbabilitiesValid(const std::vector<double>& probabilities) const
{
- typedef std::vector<double>::const_iterator Iterator;
double sum = probabilities.empty() ? 1.0 : 0.0;
- for(Iterator it = probabilities.begin(); it != probabilities.end(); ++it){
+ for (const double it : probabilities) {
//The probability must be in [0, 1.0]
- if(*it < 0.0 || *it > 1.0) {
+ if (it < 0.0 || it > 1.0) {
isc_throw(InvalidProbValue,
"probability must be in the range 0..1");
}
- sum += *it;
+ sum += it;
}
double epsilon = 0.0001;
// The sum must be equal to 1
- if (std::fabs(sum - 1.0) >= epsilon) {
- isc_throw(SumNotOne, "Sum of probabilities is not equal to 1");
- }
+ if (std::fabs(sum - 1.0) >= epsilon) {
+ isc_throw(SumNotOne, "Sum of probabilities is not equal to 1");
+ }
- return true;
+ return;
}
std::vector<double> cumulative_; ///< Partial sum of the probabilities
- boost::mt19937 rng_; ///< Mersenne Twister: A 623-dimensionally equidistributed uniform pseudo-random number generator
+ boost::mt19937 rng_; ///< Mersenne Twister: A 623-dimensionally equidistributed uniform pseudo-random number generator
boost::uniform_real<> dist_; ///< Uniformly distributed real numbers
// Shortcut typedef
-// Copyright (C) 2009-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2009-2020 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
for (int i = 0; i < sizeof(testdata); i ++) {
EXPECT_EQ(testdata[i], obuffer[i]);
}
-#ifdef EXPECT_DEATH
- // We use assert now, so we check it dies
- if (!isc::util::unittests::runningOnValgrind()) {
- EXPECT_DEATH({
- isc::util::unittests::dontCreateCoreDumps();
-
- try {
- obuffer[sizeof(testdata)];
- } catch (...) {
- // Prevent exceptions killing the application, we need
- // to make sure it dies the real hard way
- }
- }, "");
- }
-#endif
+ EXPECT_THROW(obuffer[sizeof(testdata)], isc::util::InvalidBufferPosition);
}
TEST_F(BufferTest, outputBufferClear) {