diff options
author | Francis Dupont <fdupont@isc.org> | 2024-03-10 00:23:20 +0100 |
---|---|---|
committer | Francis Dupont <fdupont@isc.org> | 2024-03-10 00:23:20 +0100 |
commit | 0906ab41860ab0bad53f2826f22cca85a6f29d9d (patch) | |
tree | 463be4906eade85dfb4cf054836d2f0783cc54f2 /src/lib/dns | |
parent | [#3208] fix Makefile (diff) | |
download | kea-0906ab41860ab0bad53f2826f22cca85a6f29d9d.tar.xz kea-0906ab41860ab0bad53f2826f22cca85a6f29d9d.zip |
[#3208] Got rid of non-C++ NULL
Diffstat (limited to 'src/lib/dns')
50 files changed, 301 insertions, 305 deletions
diff --git a/src/lib/dns/labelsequence.cc b/src/lib/dns/labelsequence.cc index 33cc3ef04d..c49c2dcef4 100644 --- a/src/lib/dns/labelsequence.cc +++ b/src/lib/dns/labelsequence.cc @@ -20,7 +20,7 @@ namespace dns { LabelSequence::LabelSequence(const void* buf) { #ifdef ENABLE_DEBUG - // In non-debug mode, dereferencing the NULL pointer further below + // In non-debug mode, dereferencing the null pointer further below // will lead to a crash, so disabling this check is not // unsafe. Except for a programming mistake, this case should not // happen. diff --git a/src/lib/dns/master_lexer.cc b/src/lib/dns/master_lexer.cc index 2b521e3ab1..610ebb787e 100644 --- a/src/lib/dns/master_lexer.cc +++ b/src/lib/dns/master_lexer.cc @@ -37,7 +37,7 @@ typedef boost::shared_ptr<master_lexer_internal::InputSource> InputSourcePtr; using namespace master_lexer_internal; struct MasterLexer::MasterLexerImpl { - MasterLexerImpl() : source_(NULL), token_(MasterToken::NOT_STARTED), + MasterLexerImpl() : source_(0), token_(MasterToken::NOT_STARTED), total_size_(0), popped_size_(0), paren_count_(0), last_was_eol_(true), has_previous_(false), @@ -95,7 +95,7 @@ struct MasterLexer::MasterLexerImpl { } std::vector<InputSourcePtr> sources_; - InputSource* source_; // current source (NULL if sources_ is empty) + InputSource* source_; // current source (null if sources_ is empty) MasterToken token_; // currently recognized token (set by a state) std::vector<char> data_; // placeholder for string data @@ -130,14 +130,14 @@ MasterLexer::~MasterLexer() { bool MasterLexer::pushSource(const char* filename, std::string* error) { - if (filename == NULL) { + if (!filename) { isc_throw(InvalidParameter, - "NULL filename for MasterLexer::pushSource"); + "null filename for MasterLexer::pushSource"); } try { impl_->sources_.push_back(InputSourcePtr(new InputSource(filename))); } catch (const InputSource::OpenError& ex) { - if (error != NULL) { + if (error) { *error = ex.what(); } return (false); @@ -173,7 +173,7 @@ MasterLexer::popSource() { } impl_->popped_size_ += impl_->source_->getPosition(); impl_->sources_.pop_back(); - impl_->source_ = impl_->sources_.empty() ? NULL : + impl_->source_ = impl_->sources_.empty() ? 0 : impl_->sources_.back().get(); impl_->has_previous_ = false; } @@ -215,7 +215,7 @@ MasterLexer::getPosition() const { const MasterToken& MasterLexer::getNextToken(Options options) { - if (impl_->source_ == NULL) { + if (impl_->source_ == 0) { isc_throw(isc::InvalidOperation, "No source to read tokens from"); } // Store the current state so we can restore it in ungetToken @@ -230,7 +230,7 @@ MasterLexer::getNextToken(Options options) { // This actually handles EOF internally too. const State* state = State::start(*this, options); - if (state != NULL) { + if (state) { state->handle(*this); } // Make sure a token was produced. Since this Can Not Happen, we assert @@ -445,23 +445,23 @@ State::start(MasterLexer& lexer, MasterLexer::Options options) { if (paren_count != 0) { lexerimpl.token_ = MasterToken(MasterToken::UNBALANCED_PAREN); paren_count = 0; // reset to 0; this helps in lenient mode. - return (NULL); + return (0); } lexerimpl.token_ = MasterToken(MasterToken::END_OF_FILE); - return (NULL); + return (0); } else if (c == ' ' || c == '\t') { // If requested and we are not in (), recognize the initial space. if (lexerimpl.last_was_eol_ && paren_count == 0 && (options & MasterLexer::INITIAL_WS) != 0) { lexerimpl.last_was_eol_ = false; lexerimpl.token_ = MasterToken(MasterToken::INITIAL_WS); - return (NULL); + return (0); } } else if (c == '\n') { lexerimpl.last_was_eol_ = true; if (paren_count == 0) { // we don't recognize EOL if we are in () lexerimpl.token_ = MasterToken(MasterToken::END_OF_LINE); - return (NULL); + return (0); } } else if (c == '\r') { if (paren_count == 0) { // check if we are in () (see above) @@ -473,7 +473,7 @@ State::start(MasterLexer& lexer, MasterLexer::Options options) { return (&QSTRING_STATE); } else { lexerimpl.token_ = MasterToken(MasterToken::UNEXPECTED_QUOTES); - return (NULL); + return (0); } } else if (c == '(') { lexerimpl.last_was_eol_ = false; @@ -482,7 +482,7 @@ State::start(MasterLexer& lexer, MasterLexer::Options options) { lexerimpl.last_was_eol_ = false; if (paren_count == 0) { lexerimpl.token_ = MasterToken(MasterToken::UNBALANCED_PAREN); - return (NULL); + return (0); } --paren_count; } else if ((options & MasterLexer::NUMBER) != 0 &&isdigit(c)) { diff --git a/src/lib/dns/master_lexer.h b/src/lib/dns/master_lexer.h index ddd2da50cc..39c018fe6d 100644 --- a/src/lib/dns/master_lexer.h +++ b/src/lib/dns/master_lexer.h @@ -92,7 +92,7 @@ public: /// beg[len] is \0. This means the application can use the bytes as a /// validly nul-terminated C string if there is no intermediate nul /// character. Note also that due to this property beg is always non - /// NULL; for an empty string len will be set to 0 and beg[0] is \0. + /// null; for an empty string len will be set to 0 and beg[0] is \0. struct StringRegion { const char* beg; ///< The start address of the string size_t len; ///< The length of the string in bytes @@ -368,7 +368,7 @@ public: /// /// In the case possible system errors in opening the file (most likely /// because of specifying a non-existent or unreadable file), it returns - /// false, and if the optional \c error parameter is non NULL, it will be + /// false, and if the optional \c error parameter is non null, it will be /// set to a description of the error (any existing content of the string /// will be discarded). If opening the file succeeds, the given /// \c error parameter will be intact. @@ -378,8 +378,8 @@ public: /// by throwing an exception. See the note for the class description /// about the distinction. /// - /// \throw InvalidParameter filename is NULL - /// \param filename A non NULL string specifying a master file + /// \throw InvalidParameter filename is null + /// \param filename A non null string specifying a master file /// \param error If non null, a placeholder to set error description in /// case of failure. /// diff --git a/src/lib/dns/master_lexer_state.h b/src/lib/dns/master_lexer_state.h index b62a366cb2..be0b587767 100644 --- a/src/lib/dns/master_lexer_state.h +++ b/src/lib/dns/master_lexer_state.h @@ -34,7 +34,7 @@ namespace master_lexer_internal { /// from the initial state. /// /// If the whole lexer transition is completed within start(), it sets the -/// identified token and returns NULL; otherwise it returns a pointer to +/// identified token and returns null; otherwise it returns a pointer to /// an object of a specific state class that completes the session /// on the call of handle(). /// @@ -64,7 +64,7 @@ public: /// /// \param lexer The lexer object that holds the main context. /// \param options The options passed to getNextToken(). - /// \return A pointer to the next state object or NULL if the transition + /// \return A pointer to the next state object or null if the transition /// is completed. static const State* start(MasterLexer& lexer, MasterLexer::Options options); @@ -75,7 +75,7 @@ public: /// start(). In the usual state transition design pattern, it would /// return the next state. But as we noticed, we never have another /// state, so we simplify it by not returning anything instead of - /// returning NULL every time. + /// returning null every time. /// /// \throw MasterLexer::ReadError Unexpected I/O error /// \throw std::bad_alloc Internal resource allocation failure @@ -122,7 +122,7 @@ protected: /// /// \param lexer The lexer object that holds the main context. /// \return A pointer to the implementation class object of the given - /// lexer. This is never NULL. + /// lexer. This is never null. MasterLexer::MasterLexerImpl* getLexerImpl(MasterLexer& lexer) const { return (lexer.impl_.get()); } diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc index 3c756e9afb..0f42977e7d 100644 --- a/src/lib/dns/master_loader.cc +++ b/src/lib/dns/master_loader.cc @@ -521,7 +521,7 @@ private: MasterLoaderCallbacks callbacks_; const AddRRCallback add_callback_; boost::scoped_ptr<RRTTL> default_ttl_; // Default TTL of RRs used when - // unspecified. If NULL no default + // unspecified. If null no default // is known. boost::scoped_ptr<RRTTL> current_ttl_; // The TTL used most recently. // Initially unset. Once set @@ -841,7 +841,7 @@ MasterLoader::MasterLoaderImpl::doGenerate() { const rdata::RdataPtr rdata = rdata::createRdata(rrtype, zone_class_, generated_rdata); - // In case we get NULL, it means there was error creating the + // In case we get null, it means there was error creating the // Rdata. The errors should have been reported by callbacks_ // already. We need to decide if we want to continue or not. if (rdata) { @@ -881,7 +881,7 @@ MasterLoader::MasterLoaderImpl::handleInitialToken() { } // This means the same name as previous. - if (last_name_.get() == NULL) { + if (!last_name_) { isc_throw(InternalException, "No previous name to use in " "place of initial whitespace"); } else if (!previous_name_) { @@ -972,7 +972,7 @@ MasterLoader::MasterLoaderImpl::loadIncremental(size_t count_limit) { rdata::createRdata(rrtype, zone_class_, lexer_, &active_origin_, options_, callbacks_); - // In case we get NULL, it means there was error creating + // In case we get null, it means there was error creating // the Rdata. The errors should have been reported by // callbacks_ already. We need to decide if we want to continue // or not. diff --git a/src/lib/dns/message.cc b/src/lib/dns/message.cc index d855f4d90d..913240c583 100644 --- a/src/lib/dns/message.cc +++ b/src/lib/dns/message.cc @@ -89,7 +89,7 @@ public: Message::Mode mode_; qid_t qid_; - // We want to use NULL for [op,r]code_ to mean the code being not + // We want to use null for [op,r]code_ to mean the code being not // correctly parsed or set. We store the real code object in // xxcode_placeholder_ and have xxcode_ refer to it when the object // is valid. @@ -149,8 +149,8 @@ void MessageImpl::init() { flags_ = 0; qid_ = 0; - rcode_ = NULL; - opcode_ = NULL; + rcode_ = 0; + opcode_ = 0; edns_ = EDNSPtr(); tsig_rr_ = ConstTSIGRecordPtr(); @@ -237,11 +237,11 @@ MessageImpl::toWire(AbstractMessageRenderer& renderer, TSIGContext* tsig_ctx) { isc_throw(InvalidMessageOperation, "Message rendering attempted in non render mode"); } - if (rcode_ == NULL) { + if (!rcode_) { isc_throw(InvalidMessageOperation, "Message rendering attempted without Rcode set"); } - if (opcode_ == NULL) { + if (!opcode_) { isc_throw(InvalidMessageOperation, "Message rendering attempted without Opcode set"); } @@ -250,7 +250,7 @@ MessageImpl::toWire(AbstractMessageRenderer& renderer, TSIGContext* tsig_ctx) { // case correctly later when that happens. orig_xxx variables remember // some configured parameters of renderer in case they are needed in // truncation processing below. - const size_t tsig_len = (tsig_ctx != NULL) ? tsig_ctx->getTSIGLength() : 0; + const size_t tsig_len = (tsig_ctx ? tsig_ctx->getTSIGLength() : 0); const size_t orig_msg_len_limit = renderer.getLengthLimit(); const AbstractMessageRenderer::CompressMode orig_compress_mode = renderer.getCompressMode(); @@ -324,7 +324,7 @@ MessageImpl::toWire(AbstractMessageRenderer& renderer, TSIGContext* tsig_ctx) { // If we're adding a TSIG to a truncated message, clear all RRsets // from the message except for the question before adding the TSIG. // If even (some of) the question doesn't fit, don't include it. - if (tsig_ctx != NULL && renderer.isTruncated()) { + if (tsig_ctx && renderer.isTruncated()) { renderer.clear(); renderer.setLengthLimit(orig_msg_len_limit - tsig_len); renderer.setCompressMode(orig_compress_mode); @@ -368,7 +368,7 @@ MessageImpl::toWire(AbstractMessageRenderer& renderer, TSIGContext* tsig_ctx) { renderer.writeUint16At(arcount, header_pos); // Add TSIG, if necessary, at the end of the message. - if (tsig_ctx != NULL) { + if (tsig_ctx) { // Release the reserved space in the renderer. renderer.setLengthLimit(orig_msg_len_limit); @@ -433,7 +433,7 @@ Message::setQid(qid_t qid) { const Rcode& Message::getRcode() const { - if (impl_->rcode_ == NULL) { + if (!impl_->rcode_) { isc_throw(InvalidMessageOperation, "getRcode attempted before set"); } return (*impl_->rcode_); @@ -450,7 +450,7 @@ Message::setRcode(const Rcode& rcode) { const Opcode& Message::getOpcode() const { - if (impl_->opcode_ == NULL) { + if (!impl_->opcode_) { isc_throw(InvalidMessageOperation, "getOpcode attempted before set"); } return (*impl_->opcode_); @@ -501,7 +501,7 @@ void Message::addRRset(const Section section, RRsetPtr rrset) { if (!rrset) { isc_throw(InvalidParameter, - "NULL RRset is given to Message::addRRset"); + "null RRset is given to Message::addRRset"); } if (impl_->mode_ != Message::RENDER) { isc_throw(InvalidMessageOperation, @@ -886,11 +886,11 @@ struct SectionFormatter { string Message::toText() const { - if (impl_->rcode_ == NULL) { + if (!impl_->rcode_) { isc_throw(InvalidMessageOperation, "Message::toText() attempted without Rcode set"); } - if (impl_->opcode_ == NULL) { + if (!impl_->opcode_) { isc_throw(InvalidMessageOperation, "Message::toText() attempted without Opcode set"); } @@ -933,15 +933,15 @@ Message::toText() const { lexical_cast<string>(impl_->counts_[SECTION_AUTHORITY]); unsigned int arcount = impl_->counts_[SECTION_ADDITIONAL]; - if (impl_->edns_ != NULL) { + if (impl_->edns_) { ++arcount; } - if (impl_->tsig_rr_ != NULL) { + if (impl_->tsig_rr_) { ++arcount; } s += ", ADDITIONAL: " + lexical_cast<string>(arcount) + "\n"; - if (impl_->edns_ != NULL) { + if (impl_->edns_) { s += "\n;; OPT PSEUDOSECTION:\n"; s += impl_->edns_->toText(); } @@ -975,7 +975,7 @@ Message::toText() const { SectionFormatter<RRsetPtr>(SECTION_ADDITIONAL, s)); } - if (impl_->tsig_rr_ != NULL) { + if (impl_->tsig_rr_) { s += "\n;; TSIG PSEUDOSECTION:\n"; s += impl_->tsig_rr_->toText(); } diff --git a/src/lib/dns/message.h b/src/lib/dns/message.h index 5bd9e00ebe..7e942413c9 100644 --- a/src/lib/dns/message.h +++ b/src/lib/dns/message.h @@ -94,7 +94,7 @@ public: using pointer = T*; using reference = T&; - SectionIterator() : impl_(NULL) {} + SectionIterator() : impl_(0) {} SectionIterator(const SectionIteratorImpl<T>& impl); ~SectionIterator(); SectionIterator(const SectionIterator<T>& source); @@ -386,7 +386,7 @@ public: /// /// \exception InvalidMessageOperation Message is not in the PARSE mode. /// - /// \return A pointer to the stored \c TSIGRecord or \c NULL. + /// \return A pointer to the stored \c TSIGRecord or null. const TSIGRecord* getTSIGRecord() const; /// \brief Returns the number of RRs contained in the given section. @@ -463,13 +463,13 @@ public: /// data before inserting RRsets. The caller is responsible for /// checking for these (see \c hasRRset() below). /// - /// \throw InvalidParameter rrset is NULL + /// \throw InvalidParameter rrset is null /// \throw InvalidMessageOperation The message is not in the \c RENDER /// mode. /// \throw OutOfRange \c section doesn't specify a valid \c Section value. /// /// \param section The message section to which the rrset is to be added - /// \param rrset The rrset to be added. Must not be NULL. + /// \param rrset The rrset to be added. Must not be null. void addRRset(const Section section, RRsetPtr rrset); /// \brief Determine whether the given section already has an RRset @@ -556,7 +556,7 @@ public: /// \c Rcode must have been set beforehand; otherwise, an exception of /// class \c InvalidMessageOperation will be thrown. /// - /// If a non-NULL \c tsig_ctx is passed, it will also add a TSIG RR + /// If a non-null \c tsig_ctx is passed, it will also add a TSIG RR /// with (in many cases) the TSIG MAC for the message along with the /// given TSIG context (\c tsig_ctx). The TSIG RR will be placed at /// the end of \c renderer. The \c TSIGContext at \c tsig_ctx will diff --git a/src/lib/dns/messagerenderer.cc b/src/lib/dns/messagerenderer.cc index 684c446849..ee0f7763e7 100644 --- a/src/lib/dns/messagerenderer.cc +++ b/src/lib/dns/messagerenderer.cc @@ -365,16 +365,16 @@ AbstractMessageRenderer::AbstractMessageRenderer() : void AbstractMessageRenderer::setBuffer(OutputBuffer* buffer) { - if (buffer != NULL && buffer_->getLength() != 0) { + if (buffer && buffer_->getLength() != 0) { isc_throw(isc::InvalidParameter, "MessageRenderer buffer cannot be set when in use"); } - if (buffer == NULL && buffer_ == &local_buffer_) { + if (!buffer && buffer_ == &local_buffer_) { isc_throw(isc::InvalidParameter, "Default MessageRenderer buffer cannot be reset"); } - if (buffer == NULL) { + if (!buffer) { // Reset to the default buffer, then clear other internal resources. // The order is important; we need to keep the used buffer intact. buffer_ = &local_buffer_; diff --git a/src/lib/dns/messagerenderer.h b/src/lib/dns/messagerenderer.h index 7945796987..804f5c5f28 100644 --- a/src/lib/dns/messagerenderer.h +++ b/src/lib/dns/messagerenderer.h @@ -119,7 +119,7 @@ private: /// \brief Buffer to store data. /// - /// Note that the class interface ensures this pointer is never NULL; + /// Note that the class interface ensures this pointer is never null; /// it either refers to \c local_buffer_ or to an application-supplied /// buffer by \c setBuffer(). /// @@ -182,9 +182,9 @@ public: /// This method can be used for an application that manages an output /// buffer separately from the message renderer and wants to keep reusing /// the renderer. When the renderer is associated with the default buffer - /// and the given pointer is non NULL, the given buffer will be + /// and the given pointer is non null, the given buffer will be /// (temporarily) used for subsequent message rendering; if the renderer - /// is associated with a temporary buffer and the given pointer is NULL, + /// is associated with a temporary buffer and the given pointer is null, /// the renderer will be reset with the default buffer. In the latter /// case any additional resources (possibly specific to a derived renderer /// class) will be cleared, but the temporary buffer is kept as the latest @@ -194,7 +194,7 @@ public: /// that could cause disruption such as dereferencing an invalid object. /// First, a temporary buffer must not be set when the associated buffer /// is in use, that is, any data are stored in the buffer. Also, the - /// default buffer cannot be "reset"; when NULL is specified a temporary + /// default buffer cannot be "reset"; when null is specified a temporary /// buffer must have been set beforehand. If these conditions aren't met /// an isc::InvalidParameter exception will be thrown. This method is /// exception free otherwise. @@ -202,7 +202,7 @@ public: /// \throw isc::InvalidParameter A restrictions of the method usage isn't /// met. /// - /// \param buffer A pointer to a temporary output buffer or NULL for reset + /// \param buffer A pointer to a temporary output buffer or null for reset /// it. void setBuffer(isc::util::OutputBuffer* buffer); diff --git a/src/lib/dns/name.cc b/src/lib/dns/name.cc index efdea0e10d..ac48205955 100644 --- a/src/lib/dns/name.cc +++ b/src/lib/dns/name.cc @@ -311,7 +311,7 @@ Name::Name(const std::string &namestring, bool downcase) { Name::Name(const char* namedata, size_t data_len, const Name* origin, bool downcase) { // Check validity of data - if (namedata == NULL || data_len == 0) { + if (!namedata || data_len == 0) { isc_throw(isc::InvalidParameter, "No data provided to Name constructor"); } @@ -319,7 +319,7 @@ Name::Name(const char* namedata, size_t data_len, const Name* origin, // It is safe to check now, we know there's at least one character. const bool absolute = (namedata[data_len - 1] == '.'); // If we are not absolute, we need the origin to complete the name. - if (!absolute && origin == NULL) { + if (!absolute && !origin) { isc_throw(MissingNameOrigin, "No origin available and name is relative"); } diff --git a/src/lib/dns/name.h b/src/lib/dns/name.h index 226fa79995..aa36348e7e 100644 --- a/src/lib/dns/name.h +++ b/src/lib/dns/name.h @@ -84,11 +84,11 @@ public: NameParserException(file, line, what) {} }; -/// \brief Thrown when origin is NULL and is needed. +/// \brief Thrown when origin is null and is needed. /// /// The exception is thrown when the Name constructor for master file /// is used, the provided data is relative and the origin parameter is -/// set to NULL. +/// set to null. class MissingNameOrigin : public NameParserException { public: MissingNameOrigin(const char* file, size_t line, const char* what) : @@ -257,7 +257,7 @@ public: /// This acts similar to the above. But the data is passed as raw C-string /// instead of wrapped-up C++ std::string. /// - /// Also, when the origin is non-NULL and the name_data is not ending with + /// Also, when the origin is non-null and the name_data is not ending with /// a dot, it is considered relative and the origin is appended to it. /// /// If the name_data is equal to "@", the content of origin is copied. @@ -265,13 +265,13 @@ public: /// \param name_data The raw data of the name. /// \param data_len How many bytes in name_data is valid and considered /// part of the name. - /// \param origin If non-NULL, it is taken as the origin to complete + /// \param origin If non-null, it is taken as the origin to complete /// relative names. /// \param downcase Whether to convert upper case letters to lower case. /// \throw NameParserException or any of its descendants in case the /// input data is invalid. - /// \throw isc::InvalidParameter In case name_data is NULL or data_len is - /// 0. + /// \throw isc::InvalidParameter In case name_data is null or + /// data_len is 0. /// \throw std::bad_alloc In case allocation fails. /// \note This constructor is specially designed for the use of master /// file parser. It mimics the behaviour of names in the master file diff --git a/src/lib/dns/rdata.cc b/src/lib/dns/rdata.cc index 6546c5d754..b175dfa406 100644 --- a/src/lib/dns/rdata.cc +++ b/src/lib/dns/rdata.cc @@ -95,7 +95,7 @@ fromtextError(bool& error_issued, const MasterLexer& lexer, } error_issued = true; - if (token == NULL) { + if (!token) { callbacks.error(lexer.getSourceName(), lexer.getSourceLine(), "createRdata from text failed: " + string(reason)); return; @@ -140,7 +140,7 @@ createRdata(const RRType& rrtype, const RRClass& rrclass, // Catching all isc::Exception is too broad, but right now we don't // have better granularity. When we complete #2518 we can make this // finer. - fromtextError(error_issued, lexer, callbacks, NULL, ex.what()); + fromtextError(error_issued, lexer, callbacks, 0, ex.what()); } // Other exceptions mean a serious implementation bug or fatal system // error; it doesn't make sense to catch and try to recover from them @@ -158,7 +158,7 @@ createRdata(const RRType& rrtype, const RRClass& rrclass, "file does not end with newline"); return (rdata); default: - rdata.reset(); // we'll return NULL + rdata.reset(); // we'll return null fromtextError(error_issued, lexer, callbacks, &token, "extra input text"); // Continue until we see EOL or EOF diff --git a/src/lib/dns/rdata.h b/src/lib/dns/rdata.h index 01201a8e74..0ee7be8c8e 100644 --- a/src/lib/dns/rdata.h +++ b/src/lib/dns/rdata.h @@ -505,7 +505,7 @@ RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass, /// cases quite differently from other versions. It internally catches /// most of syntax and semantics errors of the input (reported as exceptions), /// calls the corresponding callback specified by the \c callbacks parameters, -/// and returns a NULL smart pointer. If the caller rather wants to get +/// and returns a null smart pointer. If the caller rather wants to get /// an exception in these cases, it can pass a callback that internally /// throws on error. Some critical exceptions such as \c std::bad_alloc are /// still propagated to the upper layer as it doesn't make sense to try @@ -522,14 +522,14 @@ RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass, /// \param rrclass An \c RRClass object specifying the type/class pair. /// \param lexer A \c MasterLexer object parsing a master file for the /// RDATA to be created -/// \param origin If non NULL, specifies the origin of any domain name fields +/// \param origin If non null, specifies the origin of any domain name fields /// of the RDATA that are non absolute. /// \param options Master loader options controlling how to deal with errors /// or non critical issues in the parsed RDATA. /// \param callbacks Callback to be called when an error or non critical issue /// is found. /// \return An \c RdataPtr object pointing to the created -/// \c Rdata object. Will be NULL if parsing fails. +/// \c Rdata object. Will be null if parsing fails. RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass, MasterLexer& lexer, const Name* origin, MasterLoader::Options options, diff --git a/src/lib/dns/rdataclass.cc b/src/lib/dns/rdataclass.cc index 39df1bcc1f..627bb025c5 100644 --- a/src/lib/dns/rdataclass.cc +++ b/src/lib/dns/rdataclass.cc @@ -237,7 +237,7 @@ TSIG::TSIG(const std::string& tsig_str) { MasterLexer lexer; lexer.pushSource(ss); - impl_ = constructFromLexer(lexer, NULL); + impl_ = constructFromLexer(lexer, 0); if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) { isc_throw(InvalidRdataText, @@ -335,11 +335,10 @@ TSIG::TSIG(const Name& algorithm, uint64_t time_signed, uint16_t fudge, isc_throw(OutOfRange, "TSIG Time Signed is too large: " << time_signed); } - if ((mac_size == 0 && mac != NULL) || (mac_size > 0 && mac == NULL)) { + if ((mac_size == 0 && mac) || (mac_size > 0 && !mac)) { isc_throw(InvalidParameter, "TSIG MAC size and data inconsistent"); } - if ((other_len == 0 && other_data != NULL) || - (other_len > 0 && other_data == NULL)) { + if ((other_len == 0 && other_data) || (other_len > 0 && !other_data)) { isc_throw(InvalidParameter, "TSIG Other data length and data inconsistent"); } @@ -542,7 +541,7 @@ TSIG::getMAC() const { if (!impl_->mac_.empty()) { return (&impl_->mac_[0]); } else { - return (NULL); + return (0); } } @@ -566,7 +565,7 @@ TSIG::getOtherData() const { if (!impl_->other_data_.empty()) { return (&impl_->other_data_[0]); } else { - return (NULL); + return (0); } } @@ -596,7 +595,7 @@ NS::NS(const std::string& namestr) : MasterLexer lexer; lexer.pushSource(ss); - nsname_ = createNameFromLexer(lexer, NULL); + nsname_ = createNameFromLexer(lexer, 0); if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) { isc_throw(InvalidRdataText, "extra input text for NS: " @@ -618,7 +617,7 @@ NS::NS(InputBuffer& buffer, size_t) : /// /// The \c lexer should point to the beginning of valid textual /// representation of an NS RDATA. The NSDNAME field can be -/// non-absolute if \c origin is non-NULL, in which case \c origin is +/// non-absolute if \c origin is non-null, in which case \c origin is /// used to make it absolute. It must not be represented as a quoted /// string. /// @@ -628,7 +627,7 @@ NS::NS(InputBuffer& buffer, size_t) : /// /// \param lexer A \c MasterLexer object parsing a master file for the /// RDATA to be created -/// \param origin If non NULL, specifies the origin of NSDNAME when it +/// \param origin If non null, specifies the origin of NSDNAME when it /// is non-absolute. NS::NS(MasterLexer& lexer, const Name* origin, MasterLoader::Options, MasterLoaderCallbacks&) : @@ -865,7 +864,7 @@ PTR::PTR(const std::string& type_str) : MasterLexer lexer; lexer.pushSource(ss); - ptr_name_ = createNameFromLexer(lexer, NULL); + ptr_name_ = createNameFromLexer(lexer, 0); if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) { isc_throw(InvalidRdataText, "extra input text for PTR: " @@ -887,7 +886,7 @@ PTR::PTR(InputBuffer& buffer, size_t) : /// /// The \c lexer should point to the beginning of valid textual /// representation of a PTR RDATA. The PTRDNAME field can be -/// non-absolute if \c origin is non-NULL, in which case \c origin is +/// non-absolute if \c origin is non-null, in which case \c origin is /// used to make it absolute. It must not be represented as a quoted /// string. /// @@ -897,7 +896,7 @@ PTR::PTR(InputBuffer& buffer, size_t) : /// /// \param lexer A \c MasterLexer object parsing a master file for the /// RDATA to be created -/// \param origin If non NULL, specifies the origin of PTRDNAME when it +/// \param origin If non null, specifies the origin of PTRDNAME when it /// is non-absolute. PTR::PTR(MasterLexer& lexer, const Name* origin, MasterLoader::Options, MasterLoaderCallbacks&) : @@ -1049,7 +1048,7 @@ RRSIG::RRSIG(const std::string& rrsig_str) { MasterLexer lexer; lexer.pushSource(iss); - impl_ = constructFromLexer(lexer, NULL); + impl_ = constructFromLexer(lexer, 0); if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) { isc_throw(InvalidRdataText, "extra input text for RRSIG: " @@ -1065,7 +1064,7 @@ RRSIG::RRSIG(const std::string& rrsig_str) { /// /// The \c lexer should point to the beginning of valid textual representation /// of an RRSIG RDATA. The Signer's Name fields can be non absolute if \c -/// origin is non NULL, in which case \c origin is used to make it absolute. +/// origin is non null, in which case \c origin is used to make it absolute. /// This must not be represented as a quoted string. /// /// The Original TTL field is a valid decimal representation of an unsigned @@ -1078,7 +1077,7 @@ RRSIG::RRSIG(const std::string& rrsig_str) { /// /// \param lexer A \c MasterLexer object parsing a master file for the /// RDATA to be created -/// \param origin If non NULL, specifies the origin of Signer's Name when +/// \param origin If non null, specifies the origin of Signer's Name when /// it is non absolute. RRSIG::RRSIG(MasterLexer& lexer, const Name* origin, MasterLoader::Options, MasterLoaderCallbacks&) { @@ -1270,8 +1269,8 @@ SOA::SOA(const std::string& soastr) : MasterLexer lexer; lexer.pushSource(ss); - mname_ = createNameFromLexer(lexer, NULL); - rname_ = createNameFromLexer(lexer, NULL); + mname_ = createNameFromLexer(lexer, 0); + rname_ = createNameFromLexer(lexer, 0); fillParameters(lexer, numdata_); if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) { @@ -1288,7 +1287,7 @@ SOA::SOA(const std::string& soastr) : /// /// The \c lexer should point to the beginning of valid textual representation /// of an SOA RDATA. The MNAME and RNAME fields can be non absolute if -/// \c origin is non NULL, in which case \c origin is used to make them +/// \c origin is non null, in which case \c origin is used to make them /// absolute. These must not be represented as a quoted string. /// /// The REFRESH, RETRY, EXPIRE, and MINIMUM fields can be either a valid @@ -1301,7 +1300,7 @@ SOA::SOA(const std::string& soastr) : /// /// \param lexer A \c MasterLexer object parsing a master file for the /// RDATA to be created -/// \param origin If non NULL, specifies the origin of MNAME and RNAME when +/// \param origin If non null, specifies the origin of MNAME and RNAME when /// they are non absolute. SOA::SOA(MasterLexer& lexer, const Name* origin, MasterLoader::Options, MasterLoaderCallbacks&) : @@ -2143,7 +2142,7 @@ string A::toText() const { char addr_string[sizeof("255.255.255.255")]; - if (inet_ntop(AF_INET, &addr_, addr_string, sizeof(addr_string)) == NULL) { + if (inet_ntop(AF_INET, &addr_, addr_string, sizeof(addr_string)) == 0) { isc_throw(Unexpected, "Failed to convert IN/A RDATA to textual IPv4 address"); } @@ -2259,8 +2258,7 @@ string AAAA::toText() const { char addr_string[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")]; - if (inet_ntop(AF_INET6, &addr_, addr_string, sizeof(addr_string)) - == NULL) { + if (inet_ntop(AF_INET6, &addr_, addr_string, sizeof(addr_string)) == 0) { isc_throw(Unexpected, "Failed to convert IN/AAAA RDATA to textual IPv6 address"); } diff --git a/src/lib/dns/rdataclass.h b/src/lib/dns/rdataclass.h index 9e219eed81..9e3dd423a8 100644 --- a/src/lib/dns/rdataclass.h +++ b/src/lib/dns/rdataclass.h @@ -69,9 +69,9 @@ public: /// otherwise, an exception of type \c OutOfRange will be thrown. /// /// \c mac_size and \c mac correspond to the MAC Size and MAC fields, - /// respectively. When the MAC field is empty, \c mac must be NULL. + /// respectively. When the MAC field is empty, \c mac must be null. /// \c mac_size and \c mac must be consistent %in that \c mac_size is 0 if - /// and only if \c mac is NULL; otherwise an exception of type + /// and only if \c mac is null; otherwise an exception of type /// InvalidParameter will be thrown. /// /// The same restriction applies to \c other_len and \c other_data, @@ -121,7 +121,7 @@ public: /// \brief Return the value of the MAC field. /// - /// If the MAC field is empty, it returns NULL. + /// If the MAC field is empty, it returns null. /// Otherwise, the memory region beginning at the address returned by /// this method is valid up to the bytes specified by the return value /// of \c getMACSize(). @@ -180,7 +180,7 @@ namespace detail { /// /// \param lexer A \c MasterLexer object. Its next token is expected to be /// a string that represent a domain name. -/// \param origin If non NULL, specifies the origin of the name to be +/// \param origin If non null, specifies the origin of the name to be /// constructed. /// /// \return A new Name object that corresponds to the next string token of diff --git a/src/lib/dns/rrclass.cc b/src/lib/dns/rrclass.cc index b01f86ede1..8a0cfed26b 100644 --- a/src/lib/dns/rrclass.cc +++ b/src/lib/dns/rrclass.cc @@ -61,7 +61,7 @@ RRClass::createFromText(const string& class_str) { class_code)) { return (new RRClass(class_code)); } - return (NULL); + return (0); } ostream& diff --git a/src/lib/dns/rrclass.h b/src/lib/dns/rrclass.h index 7ac7f3491a..e57d458167 100644 --- a/src/lib/dns/rrclass.h +++ b/src/lib/dns/rrclass.h @@ -152,7 +152,7 @@ public: /// /// If the given text represents a valid RRClass, it returns a /// pointer to a new \c RRClass object. If the given text does not - /// represent a valid RRClass, it returns \c NULL. + /// represent a valid RRClass, it returns null. /// /// One main purpose of this function is to minimize the overhead /// when the given text does not represent a valid RR class. For @@ -167,8 +167,7 @@ public: /// This function never throws the \c InvalidRRClass exception. /// /// \param class_str A string representation of the \c RRClass. - /// \return A new RRClass object for the given text or a \c NULL - /// value. + /// \return A new RRClass object for the given text or a null value. static RRClass* createFromText(const std::string& class_str); /// diff --git a/src/lib/dns/rrparamregistry.cc b/src/lib/dns/rrparamregistry.cc index 2a485306a8..597f0b6b1c 100644 --- a/src/lib/dns/rrparamregistry.cc +++ b/src/lib/dns/rrparamregistry.cc @@ -577,7 +577,7 @@ findRdataFactory(RRParamRegistryImpl* reg_impl, return (genfound->second.get()); } - return (NULL); + return (0); } } @@ -589,7 +589,7 @@ RRParamRegistry::createRdata(const RRType& rrtype, const RRClass& rrclass, const AbstractRdataFactory* factory = findRdataFactory(impl_.get(), rrtype, rrclass); - if (factory != NULL) { + if (factory) { return (factory->create(rdata_string)); } @@ -601,7 +601,7 @@ RRParamRegistry::createRdata(const RRType& rrtype, const RRClass& rrclass, InputBuffer& buffer, size_t rdata_len) { const AbstractRdataFactory* factory = findRdataFactory(impl_.get(), rrtype, rrclass); - if (factory != NULL) { + if (factory) { return (factory->create(buffer, rdata_len)); } @@ -613,7 +613,7 @@ RRParamRegistry::createRdata(const RRType& rrtype, const RRClass& rrclass, const Rdata& source) { const AbstractRdataFactory* factory = findRdataFactory(impl_.get(), rrtype, rrclass); - if (factory != NULL) { + if (factory) { return (factory->create(source)); } @@ -628,7 +628,7 @@ RRParamRegistry::createRdata(const RRType& rrtype, const RRClass& rrclass, MasterLoaderCallbacks& callbacks) { const AbstractRdataFactory* factory = findRdataFactory(impl_.get(), rrtype, rrclass); - if (factory != NULL) { + if (factory) { return (factory->create(lexer, name, options, callbacks)); } diff --git a/src/lib/dns/rrparamregistry.h b/src/lib/dns/rrparamregistry.h index 578b5ab3e9..0b5286ed5f 100644 --- a/src/lib/dns/rrparamregistry.h +++ b/src/lib/dns/rrparamregistry.h @@ -523,7 +523,7 @@ public: /// the Rdata; it doesn't update the lexer to reach the end of line or /// file or doesn't care about whether there's an extra (garbage) token /// after the textual RDATA representation. Another difference is that - /// this method can throw on error and never returns a NULL pointer. + /// this method can throw on error and never returns a null pointer. /// /// For other details and parameters, see the description of /// \c rdata::createRdata(). diff --git a/src/lib/dns/rrttl.cc b/src/lib/dns/rrttl.cc index 3b543293dd..8747414d70 100644 --- a/src/lib/dns/rrttl.cc +++ b/src/lib/dns/rrttl.cc @@ -56,7 +56,7 @@ namespace { bool parseTTLString(const string& ttlstr, uint32_t& ttlval, string* error_txt) { if (ttlstr.empty()) { - if (error_txt != NULL) { + if (error_txt) { *error_txt = "Empty TTL string"; } return (false); @@ -78,7 +78,7 @@ parseTTLString(const string& ttlstr, uint32_t& ttlval, string* error_txt) { if (unit == end) { if (units_mode) { // We had some units before. The last one is missing unit. - if (error_txt != NULL) { + if (error_txt) { *error_txt = "Missing the last unit: " + ttlstr; } return (false); @@ -104,7 +104,7 @@ parseTTLString(const string& ttlstr, uint32_t& ttlval, string* error_txt) { } } if (!found) { - if (error_txt != NULL) { + if (error_txt) { *error_txt = "Unknown unit used: " + boost::lexical_cast<string>(*unit) + " in: " + ttlstr; } @@ -112,7 +112,7 @@ parseTTLString(const string& ttlstr, uint32_t& ttlval, string* error_txt) { } // Now extract the number. if (unit == pos) { - if (error_txt != NULL) { + if (error_txt) { *error_txt = "Missing number in TTL: " + ttlstr; } return (false); @@ -120,7 +120,7 @@ parseTTLString(const string& ttlstr, uint32_t& ttlval, string* error_txt) { const uint64_t value = boost::lexical_cast<uint64_t>(string(pos, unit)); if (value > max_allowed) { - if (error_txt != NULL) { + if (error_txt) { *error_txt = "Part of TTL out of range: " + ttlstr; } return (false); @@ -136,7 +136,7 @@ parseTTLString(const string& ttlstr, uint32_t& ttlval, string* error_txt) { // grow, so if we get out of range now, it won't get better, so // there's no need to continue). if (val < seconds || val > 0xffffffff) { - if (error_txt != NULL) { + if (error_txt) { *error_txt = "Part of TTL out of range: " + ttlstr; } return (false); @@ -145,7 +145,7 @@ parseTTLString(const string& ttlstr, uint32_t& ttlval, string* error_txt) { pos = unit + 1; } } catch (const boost::bad_lexical_cast&) { - if (error_txt != NULL) { + if (error_txt) { *error_txt = "invalid TTL: " + ttlstr; } return (false); @@ -155,7 +155,7 @@ parseTTLString(const string& ttlstr, uint32_t& ttlval, string* error_txt) { ttlval = val; } else { // This could be due to negative numbers in input, etc. - if (error_txt != NULL) { + if (error_txt) { *error_txt = "TTL out of range: " + ttlstr; } return (false); @@ -175,10 +175,10 @@ RRTTL::RRTTL(const std::string& ttlstr) { RRTTL* RRTTL::createFromText(const string& ttlstr) { uint32_t ttlval; - if (parseTTLString(ttlstr, ttlval, NULL)) { + if (parseTTLString(ttlstr, ttlval, 0)) { return (new RRTTL(ttlval)); } - return (NULL); + return (0); } RRTTL::RRTTL(InputBuffer& buffer) { diff --git a/src/lib/dns/rrttl.h b/src/lib/dns/rrttl.h index d6675ec702..8163c02251 100644 --- a/src/lib/dns/rrttl.h +++ b/src/lib/dns/rrttl.h @@ -104,7 +104,7 @@ public: /// /// If the given text represents a valid RRTTL, it returns a pointer /// to a new RRTTL object. If the given text does not represent a - /// valid RRTTL, it returns \c NULL.. + /// valid RRTTL, it returns null.. /// /// One main purpose of this function is to minimize the overhead /// when the given text does not represent a valid RR TTL. For this @@ -118,7 +118,7 @@ public: /// This function never throws the \c InvalidRRTTL exception. /// /// \param ttlstr A string representation of the \c RRTTL. - /// \return A new RRTTL object for the given text or a \c NULL value. + /// \return A new RRTTL object for the given text or a null value. static RRTTL* createFromText(const std::string& ttlstr); /// //@} diff --git a/src/lib/dns/tests/edns_unittest.cc b/src/lib/dns/tests/edns_unittest.cc index dfc68cc67e..c8acc9ef16 100644 --- a/src/lib/dns/tests/edns_unittest.cc +++ b/src/lib/dns/tests/edns_unittest.cc @@ -39,7 +39,7 @@ const uint8_t EDNS::SUPPORTED_VERSION; namespace { class EDNSTest : public ::testing::Test { protected: - EDNSTest() : rrtype(RRType::OPT()), buffer(NULL, 0), obuffer(0), rcode(0) { + EDNSTest() : rrtype(RRType::OPT()), buffer(0, 0), obuffer(0), rcode(0) { opt_rdata = ConstRdataPtr(new generic::OPT()); edns_base.setUDPSize(4096); } diff --git a/src/lib/dns/tests/labelsequence_unittest.cc b/src/lib/dns/tests/labelsequence_unittest.cc index 15650fac07..3fa0cc61a5 100644 --- a/src/lib/dns/tests/labelsequence_unittest.cc +++ b/src/lib/dns/tests/labelsequence_unittest.cc @@ -668,21 +668,21 @@ const char* const root_servers[] = { "d.root-servers.net", "e.root-servers.net", "f.root-servers.net", "g.root-servers.net", "h.root-servers.net", "i.root-servers.net", "j.root-servers.net", "k.root-servers.net", "l.root-servers.net", - "m.root-servers.net", NULL + "m.root-servers.net", 0 }; const char* const jp_servers[] = { "a.dns.jp", "b.dns.jp", "c.dns.jp", "d.dns.jp", "e.dns.jp", - "f.dns.jp", "g.dns.jp", NULL + "f.dns.jp", "g.dns.jp", 0 }; const char* const cn_servers[] = { "a.dns.cn", "b.dns.cn", "c.dns.cn", "d.dns.cn", "e.dns.cn", - "ns.cernet.net", NULL + "ns.cernet.net", 0 }; const char* const ca_servers[] = { "k.ca-servers.ca", "e.ca-servers.ca", "a.ca-servers.ca", "z.ca-servers.ca", "tld.isc-sns.net", "c.ca-servers.ca", "j.ca-servers.ca", "l.ca-servers.ca", - "sns-pb.isc.org", "f.ca-servers.ca", NULL + "sns-pb.isc.org", "f.ca-servers.ca", 0 }; // A helper function used in the getHash test below. @@ -695,7 +695,7 @@ hashDistributionCheck(const char* const* servers) { // Store all test names and their super domain names (excluding the // "root" label) in the set, calculates their hash values, and increments // the counter for the corresponding hash "bucket". - for (size_t i = 0; servers[i] != NULL; ++i) { + for (size_t i = 0; servers[i]; ++i) { const Name name(servers[i]); for (size_t l = 0; l < name.getLabelCount() - 1; ++l) { pair<set<Name>::const_iterator, bool> ret = @@ -875,7 +875,7 @@ TEST_F(LabelSequenceTest, serialize) { // These checks are enabled only in debug mode in the LabelSequence // class. TEST_F(LabelSequenceTest, badDeserialize) { - EXPECT_THROW(LabelSequence(NULL), isc::BadValue); + EXPECT_THROW(LabelSequence(0), isc::BadValue); const uint8_t zero_offsets[] = { 0 }; EXPECT_THROW(LabelSequence ls(zero_offsets), isc::BadValue); const uint8_t toomany_offsets[] = { Name::MAX_LABELS + 1 }; diff --git a/src/lib/dns/tests/master_lexer_state_unittest.cc b/src/lib/dns/tests/master_lexer_state_unittest.cc index e810136068..147b47be23 100644 --- a/src/lib/dns/tests/master_lexer_state_unittest.cc +++ b/src/lib/dns/tests/master_lexer_state_unittest.cc @@ -23,7 +23,7 @@ typedef MasterToken Token; // shortcut class MasterLexerStateTest : public ::testing::Test { protected: MasterLexerStateTest() : common_options(MasterLexer::INITIAL_WS), - s_null(NULL), + s_null(0), s_crlf(State::getInstance(State::CRLF)), s_string(State::getInstance(State::String)), s_qstring(State::getInstance(State::QString)), @@ -268,7 +268,7 @@ stringTokenCheck(const std::string& expected, const MasterToken& token, EXPECT_EQ(expected, actual); // There should be "hidden" nul-terminator after the string data. - ASSERT_NE(static_cast<const char*>(NULL), token.getStringRegion().beg); + ASSERT_NE(static_cast<const char*>(0), token.getStringRegion().beg); EXPECT_EQ(0, *(token.getStringRegion().beg + token.getStringRegion().len)); } diff --git a/src/lib/dns/tests/master_lexer_unittest.cc b/src/lib/dns/tests/master_lexer_unittest.cc index 7bebb48bbe..ad7e97cfc3 100644 --- a/src/lib/dns/tests/master_lexer_unittest.cc +++ b/src/lib/dns/tests/master_lexer_unittest.cc @@ -99,7 +99,7 @@ TEST_F(MasterLexerTest, pushFile) { EXPECT_EQ(0, lexer.getSourceCount()); EXPECT_EQ(143, lexer.getTotalSourceSize()); // this shouldn't change - // If we give a non NULL string pointer, its content will be intact + // If we give a non null string pointer, its content will be intact // if pushSource succeeds. std::string error_txt = "dummy"; EXPECT_TRUE(lexer.pushSource(TEST_DATA_SRCDIR "/masterload.txt", @@ -108,7 +108,7 @@ TEST_F(MasterLexerTest, pushFile) { } TEST_F(MasterLexerTest, pushBadFileName) { - EXPECT_THROW(lexer.pushSource(NULL), isc::InvalidParameter); + EXPECT_THROW(lexer.pushSource(0), isc::InvalidParameter); } TEST_F(MasterLexerTest, pushFileFail) { @@ -119,9 +119,9 @@ TEST_F(MasterLexerTest, pushFileFail) { EXPECT_FALSE(lexer.pushSource("no-such-file", &error_txt)); EXPECT_FALSE(error_txt.empty()); - // It's safe to pass NULL error_txt (either explicitly or implicitly as + // It's safe to pass null error_txt (either explicitly or implicitly as // the default) - EXPECT_FALSE(lexer.pushSource("no-such-file", NULL)); + EXPECT_FALSE(lexer.pushSource("no-such-file", 0)); EXPECT_FALSE(lexer.pushSource("no-such-file")); } diff --git a/src/lib/dns/tests/master_loader_unittest.cc b/src/lib/dns/tests/master_loader_unittest.cc index b9830072f6..74aed22cb7 100644 --- a/src/lib/dns/tests/master_loader_unittest.cc +++ b/src/lib/dns/tests/master_loader_unittest.cc @@ -178,9 +178,9 @@ TEST_F(MasterLoaderTest, include) { "$Include", "$InCluDe", "\"$INCLUDE\"", - NULL + 0 }; - for (const char** include = includes; *include != NULL; ++include) { + for (const char** include = includes; *include != 0; ++include) { SCOPED_TRACE(*include); clear(); @@ -267,9 +267,9 @@ TEST_F(MasterLoaderTest, origin) { "$Origin", "$OrigiN", "\"$ORIGIN\"", - NULL + 0 }; - for (const char** origin = origins; *origin != NULL; ++origin) { + for (const char** origin = origins; *origin != 0; ++origin) { SCOPED_TRACE(*origin); clear(); @@ -311,9 +311,9 @@ TEST_F(MasterLoaderTest, generate) { "$Generate", "$GeneratE", "\"$GENERATE\"", - NULL + 0 }; - for (const char** generate = generates; *generate != NULL; ++generate) { + for (const char** generate = generates; *generate != 0; ++generate) { SCOPED_TRACE(*generate); clear(); @@ -864,13 +864,13 @@ TEST_F(MasterLoaderTest, invalidFile) { struct ErrorCase { const char* const line; // The broken line in master file - const char* const reason; // If non NULL, the reason string + const char* const reason; // If non null, the reason string const char* const problem; // Description of the problem for SCOPED_TRACE } const error_cases[] = { - { "www... 3600 IN A 192.0.2.1", NULL, "Invalid name" }, - { "www FORTNIGHT IN A 192.0.2.1", NULL, "Invalid TTL" }, - { "www 3600 XX A 192.0.2.1", NULL, "Invalid class" }, - { "www 3600 IN A bad_ip", NULL, "Invalid Rdata" }, + { "www... 3600 IN A 192.0.2.1", 0, "Invalid name" }, + { "www FORTNIGHT IN A 192.0.2.1", 0, "Invalid TTL" }, + { "www 3600 XX A 192.0.2.1", 0, "Invalid class" }, + { "www 3600 IN A bad_ip", 0, "Invalid Rdata" }, // Parameter ordering errors { "www IN A 3600 192.168.2.7", @@ -910,27 +910,27 @@ struct ErrorCase { "createRdata from text failed: unexpected end of input", "Missing Rdata" }, - { "www 3600 IN", NULL, "Unexpected EOLN" }, + { "www 3600 IN", 0, "Unexpected EOLN" }, { "www 3600 CH TXT nothing", "Class mismatch: CH vs. IN", "Class mismatch" }, - { "www \"3600\" IN A 192.0.2.1", NULL, "Quoted TTL" }, - { "www 3600 \"IN\" A 192.0.2.1", NULL, "Quoted class" }, - { "www 3600 IN \"A\" 192.0.2.1", NULL, "Quoted type" }, - { "unbalanced)paren 3600 IN A 192.0.2.1", NULL, "Token error 1" }, - { "www 3600 unbalanced)paren A 192.0.2.1", NULL, + { "www \"3600\" IN A 192.0.2.1", 0, "Quoted TTL" }, + { "www 3600 \"IN\" A 192.0.2.1", 0, "Quoted class" }, + { "www 3600 IN \"A\" 192.0.2.1", 0, "Quoted type" }, + { "unbalanced)paren 3600 IN A 192.0.2.1", 0, "Token error 1" }, + { "www 3600 unbalanced)paren A 192.0.2.1", 0, "Token error 2" }, // Check the unknown directive. The rest looks like ordinary RR, // so we see the $ is actually special. - { "$UNKNOWN 3600 IN A 192.0.2.1", NULL, "Unknown $ directive" }, + { "$UNKNOWN 3600 IN A 192.0.2.1", 0, "Unknown $ directive" }, { "$INCLUD " TEST_DATA_SRCDIR "/example.org", "Unknown directive 'INCLUD'", "Include too short" }, { "$INCLUDES " TEST_DATA_SRCDIR "/example.org", "Unknown directive 'INCLUDES'", "Include too long" }, { "$INCLUDE", "unexpected end of input", "Missing include path" }, // The following two error messages are system dependent, omitting - { "$INCLUDE /file/not/found", NULL, "Include file not found" }, + { "$INCLUDE /file/not/found", 0, "Include file not found" }, { "$INCLUDE /file/not/found example.org. and here goes bunch of garbage", - NULL, "Include file not found and garbage at the end of line" }, + 0, "Include file not found and garbage at the end of line" }, { "$ORIGIN", "unexpected end of input", "Missing origin name" }, { "$ORIGIN invalid...name", "duplicate period in invalid...name", "Invalid name for origin" }, @@ -947,13 +947,13 @@ struct ErrorCase { { "$TTL \"100\"", "unexpected quotes", "bad TTL, quoted" }, { "$TT 100", "Unknown directive 'TT'", "bad directive, too short" }, { "$TTLLIKE 100", "Unknown directive 'TTLLIKE'", "bad directive, extra" }, - { NULL, NULL, NULL } + { 0, 0, 0 } }; // Test a broken zone is handled properly. We test several problems, // both in strict and lenient mode. TEST_F(MasterLoaderTest, brokenZone) { - for (const ErrorCase* ec = error_cases; ec->line != NULL; ++ec) { + for (const ErrorCase* ec = error_cases; ec->line; ++ec) { SCOPED_TRACE(ec->problem); const string zone(prepareZone(ec->line, true)); @@ -967,7 +967,7 @@ TEST_F(MasterLoaderTest, brokenZone) { EXPECT_THROW(loader_->load(), MasterLoaderError); EXPECT_FALSE(loader_->loadedSuccessfully()); EXPECT_EQ(1, errors_.size()); - if (ec->reason != NULL) { + if (ec->reason) { checkCallbackMessage(errors_.at(0), ec->reason, 2); } EXPECT_TRUE(warnings_.empty()); diff --git a/src/lib/dns/tests/message_unittest.cc b/src/lib/dns/tests/message_unittest.cc index db5fcd6dec..8959d8469a 100644 --- a/src/lib/dns/tests/message_unittest.cc +++ b/src/lib/dns/tests/message_unittest.cc @@ -195,7 +195,7 @@ TEST_F(MessageTest, setEDNS) { TEST_F(MessageTest, fromWireWithTSIG) { // Initially there should be no TSIG - EXPECT_EQ(static_cast<void*>(NULL), message_parse.getTSIGRecord()); + EXPECT_FALSE(message_parse.getTSIGRecord()); // getTSIGRecord() is only valid in the parse mode. EXPECT_THROW(message_render.getTSIGRecord(), InvalidMessageOperation); @@ -206,7 +206,7 @@ TEST_F(MessageTest, fromWireWithTSIG) { 0x21, 0xce, 0x6c, 0x6f, 0xff, 0x1e, 0x9e, 0xf3 }; const TSIGRecord* tsig_rr = message_parse.getTSIGRecord(); - ASSERT_NE(static_cast<void*>(NULL), tsig_rr); + ASSERT_TRUE(tsig_rr); EXPECT_EQ(Name("www.example.com"), tsig_rr->getName()); EXPECT_EQ(85, tsig_rr->getLength()); // see TSIGRecordTest.getLength EXPECT_EQ(TSIGKey::HMACMD5_NAME(), tsig_rr->getRdata().getAlgorithm()); @@ -217,18 +217,18 @@ TEST_F(MessageTest, fromWireWithTSIG) { tsig_rr->getRdata().getMACSize()); EXPECT_EQ(0, tsig_rr->getRdata().getError()); EXPECT_EQ(0, tsig_rr->getRdata().getOtherLen()); - EXPECT_EQ(static_cast<void*>(NULL), tsig_rr->getRdata().getOtherData()); + EXPECT_FALSE(tsig_rr->getRdata().getOtherData()); // If we clear the message for reuse, the recorded TSIG will be cleared. message_parse.clear(Message::PARSE); - EXPECT_EQ(static_cast<void*>(NULL), message_parse.getTSIGRecord()); + EXPECT_FALSE(message_parse.getTSIGRecord()); } TEST_F(MessageTest, fromWireWithTSIGCompressed) { // Mostly same as fromWireWithTSIG, but the TSIG owner name is compressed. factoryFromFile(message_parse, "message_fromWire12.wire"); const TSIGRecord* tsig_rr = message_parse.getTSIGRecord(); - ASSERT_NE(static_cast<void*>(NULL), tsig_rr); + ASSERT_TRUE(tsig_rr); EXPECT_EQ(Name("www.example.com"), tsig_rr->getName()); // len(www.example.com) = 17, but when fully compressed, the length is // 2 bytes. So the length of the record should be 15 bytes shorter. diff --git a/src/lib/dns/tests/messagerenderer_unittest.cc b/src/lib/dns/tests/messagerenderer_unittest.cc index c3a53eb6ca..470f3636c3 100644 --- a/src/lib/dns/tests/messagerenderer_unittest.cc +++ b/src/lib/dns/tests/messagerenderer_unittest.cc @@ -247,7 +247,7 @@ TEST_F(MessageRendererTest, setBuffer) { // Reset the buffer to the default again. Other internal states and // resources should be cleared. The used buffer should be intact. - renderer.setBuffer(NULL); + renderer.setBuffer(0); EXPECT_EQ(sizeof(uint32_t), new_buffer.getLength()); EXPECT_EQ(0, renderer.getLength()); EXPECT_EQ(512, renderer.getLengthLimit()); @@ -266,12 +266,12 @@ TEST_F(MessageRendererTest, setBufferErrors) { EXPECT_THROW(renderer.setBuffer(&new_buffer), isc::InvalidParameter); // Resetting the buffer isn't allowed for the default buffer. - renderer.setBuffer(NULL); - EXPECT_THROW(renderer.setBuffer(NULL), isc::InvalidParameter); + renderer.setBuffer(0); + EXPECT_THROW(renderer.setBuffer(0), isc::InvalidParameter); // It's okay to reset a temporary buffer without using it. renderer.setBuffer(&new_buffer); - EXPECT_NO_THROW(renderer.setBuffer(NULL)); + EXPECT_NO_THROW(renderer.setBuffer(0)); } TEST_F(MessageRendererTest, manyRRs) { diff --git a/src/lib/dns/tests/name_unittest.cc b/src/lib/dns/tests/name_unittest.cc index 636a403f38..d2417012da 100644 --- a/src/lib/dns/tests/name_unittest.cc +++ b/src/lib/dns/tests/name_unittest.cc @@ -325,7 +325,7 @@ TEST_F(NameTest, copyOrigin) { EXPECT_EQ(origin_name, Name("@", 1, &origin_name_upper, true)); EXPECT_EQ(origin_name_upper, Name("@", 1, &origin_name_upper, true)); // If we don't provide the origin, it throws - EXPECT_THROW(Name("@", 1, NULL), MissingNameOrigin); + EXPECT_THROW(Name("@", 1, 0), MissingNameOrigin); } // Test the master-file constructor does not append the origin when the @@ -336,7 +336,7 @@ TEST_F(NameTest, dontAppendOrigin) { EXPECT_EQ(example_name, Name("WWW.EXAMPLE.COM.", 16, &origin_name, true)); EXPECT_EQ(example_name_upper, Name("WWW.EXAMPLE.COM.", 16, &origin_name)); // And it does not require the origin to be provided - EXPECT_NO_THROW(Name("www.example.com.", 16, NULL)); + EXPECT_NO_THROW(Name("www.example.com.", 16, 0)); } // Test the master-file constructor properly appends the origin when @@ -350,14 +350,14 @@ TEST_F(NameTest, appendOrigin) { // Check we can prepend more than one label EXPECT_EQ(Name("a.b.c.d.example.com."), Name("a.b.c.d", 7, &origin_name)); // When the name is relative, we throw. - EXPECT_THROW(Name("www", 3, NULL), MissingNameOrigin); + EXPECT_THROW(Name("www", 3, 0), MissingNameOrigin); } // When we don't provide the data, it throws TEST_F(NameTest, noDataProvided) { - EXPECT_THROW(Name(NULL, 10, NULL), isc::InvalidParameter); - EXPECT_THROW(Name(NULL, 10, &origin_name), isc::InvalidParameter); - EXPECT_THROW(Name("www", 0, NULL), isc::InvalidParameter); + EXPECT_THROW(Name(0, 10, 0), isc::InvalidParameter); + EXPECT_THROW(Name(0, 10, &origin_name), isc::InvalidParameter); + EXPECT_THROW(Name("www", 0, 0), isc::InvalidParameter); EXPECT_THROW(Name("www", 0, &origin_name), isc::InvalidParameter); } @@ -381,7 +381,7 @@ TEST_F(NameTest, combinedTooLong) { TEST_F(NameTest, atSign) { // If it is alone, it is the origin EXPECT_EQ(origin_name, Name("@", 1, &origin_name)); - EXPECT_THROW(Name("@", 1, NULL), MissingNameOrigin); + EXPECT_THROW(Name("@", 1, 0), MissingNameOrigin); EXPECT_EQ(Name::ROOT_NAME(), Name("@")); // It is not alone. It is taken verbatim. We check the name converted @@ -389,7 +389,7 @@ TEST_F(NameTest, atSign) { // may be wrong -- if we create it wrong the same way as the tested // object. EXPECT_EQ("\\@.", Name("@.").toText()); - EXPECT_EQ("\\@.", Name("@.", 2, NULL).toText()); + EXPECT_EQ("\\@.", Name("@.", 2, 0).toText()); EXPECT_EQ("\\@something.", Name("@something").toText()); EXPECT_EQ("something\\@.", Name("something@").toText()); EXPECT_EQ("\\@x.example.com.", Name("@x", 2, &origin_name).toText()); diff --git a/src/lib/dns/tests/rdata_char_string_data_unittest.cc b/src/lib/dns/tests/rdata_char_string_data_unittest.cc index d4da8420a2..ec92d67ba6 100644 --- a/src/lib/dns/tests/rdata_char_string_data_unittest.cc +++ b/src/lib/dns/tests/rdata_char_string_data_unittest.cc @@ -132,11 +132,11 @@ const struct TestData { {"Test\x1fTest", "Test\\031Test"}, {"Test ~ Test", "Test ~ Test"}, {"Test\x7fTest", "Test\\127Test"}, - {NULL, NULL} + {0, 0} }; TEST_F(CharStringDataTest, charStringDataToString) { - for (const TestData* cur = conversion_data; cur->data != NULL; ++cur) { + for (const TestData* cur = conversion_data; cur->data; ++cur) { uint8_t idata[32]; size_t length = std::strlen(cur->data); ASSERT_LT(length, sizeof(idata)); diff --git a/src/lib/dns/tests/rdata_char_string_unittest.cc b/src/lib/dns/tests/rdata_char_string_unittest.cc index fb6de53d42..150d6369cd 100644 --- a/src/lib/dns/tests/rdata_char_string_unittest.cc +++ b/src/lib/dns/tests/rdata_char_string_unittest.cc @@ -153,11 +153,11 @@ const struct TestData { {"Test\x1fTest", "Test\\031Test"}, {"Test ~ Test", "Test ~ Test"}, {"Test\x7fTest", "Test\\127Test"}, - {NULL, NULL} + {0, 0} }; TEST_F(CharStringTest, charStringToString) { - for (const TestData* cur = conversion_data; cur->data != NULL; ++cur) { + for (const TestData* cur = conversion_data; cur->data; ++cur) { uint8_t idata[32]; size_t length = std::strlen(cur->data); // length (1 byte) + string (length bytes) diff --git a/src/lib/dns/tests/rdata_dhcid_unittest.cc b/src/lib/dns/tests/rdata_dhcid_unittest.cc index c2cedee57c..5c12829e90 100644 --- a/src/lib/dns/tests/rdata_dhcid_unittest.cc +++ b/src/lib/dns/tests/rdata_dhcid_unittest.cc @@ -104,7 +104,7 @@ TEST_F(Rdata_DHCID_Test, createFromWire) { *rdataFactoryFromFile(RRType("DHCID"), RRClass("IN"), "rdata_dhcid_fromWire"))); - InputBuffer buffer(NULL, 0); + InputBuffer buffer(0, 0); EXPECT_THROW(in::DHCID(buffer, 0), InvalidRdataLength); // TBD: more tests diff --git a/src/lib/dns/tests/rdata_ns_unittest.cc b/src/lib/dns/tests/rdata_ns_unittest.cc index 80123ae937..ca630c04b8 100644 --- a/src/lib/dns/tests/rdata_ns_unittest.cc +++ b/src/lib/dns/tests/rdata_ns_unittest.cc @@ -103,7 +103,7 @@ TEST_F(Rdata_NS_Test, createFromLexer) { *test::createRdataUsingLexer(RRType::NS(), RRClass::IN(), "ns8"))); - // Exceptions cause NULL to be returned. + // Exceptions cause null to be returned. EXPECT_FALSE(test::createRdataUsingLexer(RRType::NS(), RRClass::IN(), "")); diff --git a/src/lib/dns/tests/rdata_opt_unittest.cc b/src/lib/dns/tests/rdata_opt_unittest.cc index a235183529..d5d1519850 100644 --- a/src/lib/dns/tests/rdata_opt_unittest.cc +++ b/src/lib/dns/tests/rdata_opt_unittest.cc @@ -74,7 +74,7 @@ TEST_F(Rdata_OPT_Test, createFromWire) { } TEST_F(Rdata_OPT_Test, createFromLexer) { - // OPT RR cannot be created from text. Exceptions cause NULL to be + // OPT RR cannot be created from text. Exceptions cause null to be // returned. EXPECT_FALSE(test::createRdataUsingLexer(RRType::OPT(), RRClass::IN(), "this does not matter")); @@ -133,7 +133,7 @@ TEST_F(Rdata_OPT_Test, appendPseudoRR) { generic::OPT rdata_opt; // Append empty option data - rdata_opt.appendPseudoRR(0x0042, NULL, 0); + rdata_opt.appendPseudoRR(0x0042, 0, 0); // Append simple option data const uint8_t option_data[] = {'H', 'e', 'l', 'l', 'o'}; diff --git a/src/lib/dns/tests/rdata_rrsig_unittest.cc b/src/lib/dns/tests/rdata_rrsig_unittest.cc index b198d15c62..06f8b187a3 100644 --- a/src/lib/dns/tests/rdata_rrsig_unittest.cc +++ b/src/lib/dns/tests/rdata_rrsig_unittest.cc @@ -328,7 +328,7 @@ TEST_F(Rdata_RRSIG_Test, createFromLexer) { *test::createRdataUsingLexer(RRType::RRSIG(), RRClass::IN(), rrsig_txt))); - // Exceptions cause NULL to be returned. + // Exceptions cause null to be returned. EXPECT_FALSE(test::createRdataUsingLexer(RRType::RRSIG(), RRClass::IN(), "INVALIDINPUT")); } diff --git a/src/lib/dns/tests/rdata_soa_unittest.cc b/src/lib/dns/tests/rdata_soa_unittest.cc index f0da2436e7..f107ea9c93 100644 --- a/src/lib/dns/tests/rdata_soa_unittest.cc +++ b/src/lib/dns/tests/rdata_soa_unittest.cc @@ -56,22 +56,22 @@ TEST_F(Rdata_SOA_Test, createFromText) { // A simple case. checkFromTextSOA<isc::Exception, isc::Exception>( "ns.example.com. root.example.com. 2010012601 3600 300 3600000 1200", - NULL, false, false); + 0, false, false); // Beginning and trailing space are ignored. checkFromTextSOA<isc::Exception, isc::Exception>( " ns.example.com. root.example.com. " - "2010012601 3600 300 3600000 1200 ", NULL, false, false); + "2010012601 3600 300 3600000 1200 ", 0, false, false); // using extended TTL-like form for some parameters. checkFromTextSOA<isc::Exception, isc::Exception>( "ns.example.com. root.example.com. 2010012601 1H 5M 1000H 20M", - NULL, false, false); + 0, false, false); // multi-line. checkFromTextSOA<isc::Exception, isc::Exception>( "ns.example.com. (root.example.com.\n" - "2010012601 1H 5M 1000H) 20M", NULL, false, false); + "2010012601 1H 5M 1000H) 20M", 0, false, false); // relative names for MNAME and RNAME with a separate origin (lexer // version only) @@ -149,10 +149,10 @@ TEST_F(Rdata_SOA_Test, createFromText) { // the lexer expects a string excluding newline and EOF). checkFromTextSOA<InvalidRdataText, isc::Exception>( "ns.example.com. root.example.com. 2010012601 1H 5M 1000H 20M\n", - NULL, true, false); + 0, true, false); checkFromTextSOA<InvalidRdataText, MasterLexer::LexerError>( "\nns.example.com. root.example.com. 2010012601 1H 5M 1000H 20M", - NULL, true, true); + 0, true, true); } TEST_F(Rdata_SOA_Test, createFromWire) { diff --git a/src/lib/dns/tests/rdata_tkey_unittest.cc b/src/lib/dns/tests/rdata_tkey_unittest.cc index 8592a27a01..18bf886966 100644 --- a/src/lib/dns/tests/rdata_tkey_unittest.cc +++ b/src/lib/dns/tests/rdata_tkey_unittest.cc @@ -124,9 +124,9 @@ TEST_F(Rdata_TKEY_Test, fromText) { EXPECT_EQ(3, rdata_tkey.getMode()); EXPECT_EQ(0, rdata_tkey.getError()); EXPECT_EQ(0, rdata_tkey.getKeyLen()); - EXPECT_EQ(static_cast<void*>(0), rdata_tkey.getKey()); + EXPECT_FALSE(rdata_tkey.getKey()); EXPECT_EQ(0, rdata_tkey.getOtherLen()); - EXPECT_EQ(static_cast<void*>(0), rdata_tkey.getOtherData()); + EXPECT_FALSE(rdata_tkey.getOtherData()); generic::TKEY tkey2(valid_text2); EXPECT_EQ(12, tkey2.getKeyLen()); @@ -220,7 +220,7 @@ fromWireCommonChecks(const generic::TKEY& tkey) { tkey.getKey(), tkey.getKeyLen()); EXPECT_EQ(0, tkey.getOtherLen()); - EXPECT_EQ(static_cast<const void*>(0), tkey.getOtherData()); + EXPECT_FALSE(tkey.getOtherData()); } TEST_F(Rdata_TKEY_Test, createFromWire) { @@ -248,7 +248,7 @@ TEST_F(Rdata_TKEY_Test, createFromWireWithoutKey) { "rdata_tkey_fromWire3.wire")); const generic::TKEY& tkey(dynamic_cast<generic::TKEY&>(*rdata)); EXPECT_EQ(0, tkey.getKeyLen()); - EXPECT_EQ(static_cast<const void*>(0), tkey.getKey()); + EXPECT_FALSE(tkey.getKey()); vector<uint8_t> expect_data = { 'a', 'b', 'c', 'd', '0', '1', '2', '3' }; matchWireData(&expect_data[0], expect_data.size(), diff --git a/src/lib/dns/tests/rdata_tsig_unittest.cc b/src/lib/dns/tests/rdata_tsig_unittest.cc index 9d3bd89662..fa7be1d6a6 100644 --- a/src/lib/dns/tests/rdata_tsig_unittest.cc +++ b/src/lib/dns/tests/rdata_tsig_unittest.cc @@ -112,11 +112,11 @@ TEST_F(Rdata_TSIG_Test, fromText) { EXPECT_EQ(1286779327, rdata_tsig.getTimeSigned()); EXPECT_EQ(300, rdata_tsig.getFudge()); EXPECT_EQ(0, rdata_tsig.getMACSize()); - EXPECT_EQ(static_cast<void*>(NULL), rdata_tsig.getMAC()); + EXPECT_FALSE(rdata_tsig.getMAC()); EXPECT_EQ(16020, rdata_tsig.getOriginalID()); EXPECT_EQ(TSIGError::BAD_KEY_CODE, rdata_tsig.getError()); EXPECT_EQ(0, rdata_tsig.getOtherLen()); - EXPECT_EQ(static_cast<void*>(NULL), rdata_tsig.getOtherData()); + EXPECT_FALSE(rdata_tsig.getOtherData()); TSIG tsig2(valid_text2); EXPECT_EQ(12, tsig2.getMACSize()); @@ -206,7 +206,7 @@ fromWireCommonChecks(const TSIG& tsig) { EXPECT_EQ(2845, tsig.getOriginalID()); EXPECT_EQ(0, tsig.getOtherLen()); - EXPECT_EQ(static_cast<const void*>(NULL), tsig.getOtherData()); + EXPECT_FALSE(tsig.getOtherData()); } TEST_F(Rdata_TSIG_Test, createFromWire) { @@ -239,7 +239,7 @@ TEST_F(Rdata_TSIG_Test, createFromWireWithoutMAC) { const TSIG& tsig(dynamic_cast<TSIG&>(*rdata)); EXPECT_EQ(16, tsig.getError()); EXPECT_EQ(0, tsig.getMACSize()); - EXPECT_EQ(static_cast<const void*>(NULL), tsig.getMAC()); + EXPECT_FALSE(tsig.getMAC()); } TEST_F(Rdata_TSIG_Test, createFromWireWithCompression) { @@ -286,12 +286,12 @@ TEST_F(Rdata_TSIG_Test, copyConstruct) { TEST_F(Rdata_TSIG_Test, createFromParams) { EXPECT_EQ(0, rdata_tsig.compare(TSIG(Name("hmac-md5.sig-alg.reg.int"), - 1286779327, 300, 0, NULL, 16020, 17, 0, NULL))); + 1286779327, 300, 0, 0, 16020, 17, 0, 0))); const uint8_t fake_data[] = { 0x14, 0x02, 0x84, 0x14, 0x02, 0x84, 0x14, 0x02, 0x84, 0x14, 0x02, 0x84 }; EXPECT_EQ(0, TSIG(valid_text2).compare(TSIG(Name("hmac-sha256"), 1286779327, 300, 12, - fake_data, 16020, 16, 0, NULL))); + fake_data, 16020, 16, 0, 0))); const uint8_t fake_data2[] = { 0x14, 0x02, 0x84, 0x14, 0x02, 0x84 }; EXPECT_EQ(0, TSIG(valid_text3).compare(TSIG(Name("hmac-sha1"), 1286779327, 300, 12, @@ -299,13 +299,13 @@ TEST_F(Rdata_TSIG_Test, createFromParams) { EXPECT_THROW(TSIG(Name("hmac-sha256"), 1ULL << 48, 300, 12, fake_data, 16020, 18, 6, fake_data2), isc::OutOfRange); - EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, fake_data, 16020, 18, 0, NULL), + EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, fake_data, 16020, 18, 0, 0), isc::InvalidParameter); - EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 12, NULL, 16020, 18, 0, NULL), + EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 12, 0, 16020, 18, 0, 0), isc::InvalidParameter); - EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, NULL, 16020, 18, 0, fake_data), + EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, 0, 16020, 18, 0, fake_data), isc::InvalidParameter); - EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, NULL, 16020, 18, 6, NULL), + EXPECT_THROW(TSIG(Name("hmac-sha256"), 0, 300, 0, 0, 16020, 18, 6, 0), isc::InvalidParameter); } diff --git a/src/lib/dns/tests/rdata_txt_like_unittest.cc b/src/lib/dns/tests/rdata_txt_like_unittest.cc index 35cbf90f21..91f2735fb9 100644 --- a/src/lib/dns/tests/rdata_txt_like_unittest.cc +++ b/src/lib/dns/tests/rdata_txt_like_unittest.cc @@ -106,25 +106,25 @@ TYPED_TEST(Rdata_TXT_LIKE_Test, createFromText) { // case, then with MasterLexer. For the latter, we need to read and skip // '\n'. These apply to most of the other cases below. EXPECT_EQ(0, this->rdata_txt_like.compare(*rdata)); - EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, + EXPECT_EQ(0, TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS, this->loader_cb).compare(*rdata)); EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType()); // surrounding double-quotes shouldn't change the result. EXPECT_EQ(0, this->rdata_txt_like_quoted.compare(*rdata)); - EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, + EXPECT_EQ(0, TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS, this->loader_cb).compare(*rdata)); EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType()); // multi-line input with () EXPECT_EQ(0, TypeParam(multi_line).compare(*rdata)); - EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, + EXPECT_EQ(0, TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS, this->loader_cb).compare(*rdata)); EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType()); // for the same data using escape EXPECT_EQ(0, TypeParam(escaped_txt).compare(*rdata)); - EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, + EXPECT_EQ(0, TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS, this->loader_cb).compare(*rdata)); EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType()); @@ -135,7 +135,7 @@ TYPED_TEST(Rdata_TXT_LIKE_Test, createFromText) { this->obuffer.getData(), this->obuffer.getLength()); this->obuffer.clear(); - TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, this->loader_cb). + TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS, this->loader_cb). toWire(this->obuffer); matchWireData(wiredata_nulltxt, sizeof(wiredata_nulltxt), this->obuffer.getData(), this->obuffer.getLength()); @@ -150,7 +150,7 @@ TYPED_TEST(Rdata_TXT_LIKE_Test, createFromText) { this->obuffer.getData(), this->obuffer.getLength()); this->obuffer.clear(); - TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, this->loader_cb). + TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS, this->loader_cb). toWire(this->obuffer); matchWireData(&this->wiredata_longesttxt[0], this->wiredata_longesttxt.size(), @@ -160,14 +160,14 @@ TYPED_TEST(Rdata_TXT_LIKE_Test, createFromText) { // Too long text for a valid character-string. EXPECT_THROW(TypeParam(string(256, 'a')), CharStringTooLong); - EXPECT_THROW(TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, + EXPECT_THROW(TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS, this->loader_cb), CharStringTooLong); EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType()); // The escape character makes the double quote a part of character-string, // so this is invalid input and should be rejected. EXPECT_THROW(TypeParam("\"Test-String\\\""), InvalidRdataText); - EXPECT_THROW(TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, + EXPECT_THROW(TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS, this->loader_cb), MasterLexer::LexerError); EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType()); } @@ -201,7 +201,7 @@ TYPED_TEST(Rdata_TXT_LIKE_Test, createMultiStringsFromText) { SCOPED_TRACE(it); EXPECT_EQ(0, TypeParam(it).compare(*rdata)); - EXPECT_EQ(0, TypeParam(this->lexer, NULL, MasterLoader::MANY_ERRORS, + EXPECT_EQ(0, TypeParam(this->lexer, 0, MasterLoader::MANY_ERRORS, this->loader_cb).compare(*rdata)); EXPECT_EQ(MasterToken::END_OF_LINE, this->lexer.getNextToken().getType()); diff --git a/src/lib/dns/tests/rdata_unittest.cc b/src/lib/dns/tests/rdata_unittest.cc index 4bfa38c81b..93a58c0e4f 100644 --- a/src/lib/dns/tests/rdata_unittest.cc +++ b/src/lib/dns/tests/rdata_unittest.cc @@ -151,7 +151,7 @@ TEST_F(RdataTest, createRdataWithLexer) { // Valid case. ++line; ConstRdataPtr rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, - NULL, MasterLoader::MANY_ERRORS, + 0, MasterLoader::MANY_ERRORS, callbacks); EXPECT_EQ(0, aaaa_rdata.compare(*rdata)); EXPECT_FALSE(callback.isCalled()); @@ -160,16 +160,16 @@ TEST_F(RdataTest, createRdataWithLexer) { // It should cause any confusion. ++line; callback.clear(); - rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, + rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, 0, MasterLoader::MANY_ERRORS, callbacks); EXPECT_EQ(0, aaaa_rdata.compare(*rdata)); EXPECT_FALSE(callback.isCalled()); - // Broken RDATA text: extra token. createRdata() returns NULL, error + // Broken RDATA text: extra token. createRdata() returns null, error // callback is called. ++line; callback.clear(); - EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, + EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, 0, MasterLoader::MANY_ERRORS, callbacks)); callback.check(src_name, line, CreateRdataCallback::ERROR, "createRdata from text failed near 'extra-token': " @@ -179,7 +179,7 @@ TEST_F(RdataTest, createRdataWithLexer) { // callback. ++line; callback.clear(); - EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, + EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, 0, MasterLoader::MANY_ERRORS, callbacks)); callback.check(src_name, line, CreateRdataCallback::ERROR, "createRdata from text failed near 'extra': " @@ -188,7 +188,7 @@ TEST_F(RdataTest, createRdataWithLexer) { // Lexer error will happen, corresponding error callback will be triggered. ++line; callback.clear(); - EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, + EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, 0, MasterLoader::MANY_ERRORS, callbacks)); callback.check(src_name, line, CreateRdataCallback::ERROR, "createRdata from text failed: unbalanced parentheses"); @@ -197,7 +197,7 @@ TEST_F(RdataTest, createRdataWithLexer) { // triggered. ++line; callback.clear(); - EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, + EXPECT_FALSE(createRdata(RRType::AAAA(), RRClass::IN(), lexer, 0, MasterLoader::MANY_ERRORS, callbacks)); callback.check(src_name, line, CreateRdataCallback::ERROR, "createRdata from text failed: Bad IN/AAAA RDATA text: " @@ -207,7 +207,7 @@ TEST_F(RdataTest, createRdataWithLexer) { // file is not ended with a newline. ++line; callback.clear(); - rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL, + rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, 0, MasterLoader::MANY_ERRORS, callbacks); EXPECT_EQ(0, aaaa_rdata.compare(*rdata)); callback.check(src_name, line, CreateRdataCallback::WARN, diff --git a/src/lib/dns/tests/rdata_unittest.h b/src/lib/dns/tests/rdata_unittest.h index 74bd5c4652..fae7def42d 100644 --- a/src/lib/dns/tests/rdata_unittest.h +++ b/src/lib/dns/tests/rdata_unittest.h @@ -38,7 +38,7 @@ protected: // ExForString for the string version, and ExForLexer for the lexer // version. throw_str_version and throw_lexer_version are set to true // iff the string/lexer version is expected to throw, respectively. - // Parameter origin can be set to non NULL for the origin parameter of + // Parameter origin can be set to non null for the origin parameter of // the lexer version of Rdata constructor. template <typename RdataType, typename ExForString, typename ExForLexer> void checkFromText(const std::string& rdata_txt, diff --git a/src/lib/dns/tests/rrclass_unittest.cc b/src/lib/dns/tests/rrclass_unittest.cc index c5fb01eab0..0b4659bfba 100644 --- a/src/lib/dns/tests/rrclass_unittest.cc +++ b/src/lib/dns/tests/rrclass_unittest.cc @@ -156,9 +156,11 @@ struct ClassParam { const uint16_t code; // 1, 3, etc const RRClass& (*obj)(); // RRClass::IN(), RRClass::CH(), etc } known_classes[] = { - {"IN", 1, RRClass::IN}, {"CH", 3, RRClass::CH}, - {"NONE", 254, RRClass::NONE}, {"ANY", 255, RRClass::ANY}, - {NULL, 0, NULL} + {"IN", 1, RRClass::IN}, + {"CH", 3, RRClass::CH}, + {"NONE", 254, RRClass::NONE}, + {"ANY", 255, RRClass::ANY}, + {0, 0, 0} }; TEST(RRClassConstTest, wellKnowns) { diff --git a/src/lib/dns/tests/rrset_unittest.cc b/src/lib/dns/tests/rrset_unittest.cc index 447fed5085..c21f3bde0d 100644 --- a/src/lib/dns/tests/rrset_unittest.cc +++ b/src/lib/dns/tests/rrset_unittest.cc @@ -339,15 +339,15 @@ protected: TEST_F(RRsetRRSIGTest, getRRsig) { RRsetPtr sp = rrset_a->getRRsig(); - EXPECT_EQ(static_cast<void*>(NULL), sp.get()); + EXPECT_FALSE(sp); sp = rrset_aaaa->getRRsig(); - EXPECT_NE(static_cast<void*>(NULL), sp.get()); + EXPECT_TRUE(sp); } TEST_F(RRsetRRSIGTest, addRRsig) { RRsetPtr sp = rrset_a->getRRsig(); - EXPECT_EQ(static_cast<void*>(NULL), sp.get()); + EXPECT_FALSE(sp); rrset_rrsig = RRsetPtr(new RRset(test_name, RRClass::IN(), RRType::RRSIG(), RRTTL(3600))); @@ -362,7 +362,7 @@ TEST_F(RRsetRRSIGTest, addRRsig) { rrset_a->addRRsig(rrset_rrsig); sp = rrset_a->getRRsig(); - EXPECT_NE(static_cast<void*>(NULL), sp.get()); + EXPECT_TRUE(sp); EXPECT_EQ(2, sp->getRdataCount()); // add to existing RRSIG diff --git a/src/lib/dns/tests/rrtype_unittest.cc b/src/lib/dns/tests/rrtype_unittest.cc index d80e4a3fe2..3b24cdcf45 100644 --- a/src/lib/dns/tests/rrtype_unittest.cc +++ b/src/lib/dns/tests/rrtype_unittest.cc @@ -244,7 +244,7 @@ struct TypeParam { // Unassigned 262-32767 {"TA", 32768, []() -> const RRType& {static const RRType r("TA"); return (r);}}, {"DLV", 32769, []() -> const RRType& {static const RRType r("DLV"); return (r);}}, - {NULL, 0, NULL} + {0, 0, 0} }; TEST(RRTypeConstTest, wellKnowns) { diff --git a/src/lib/dns/tests/tsig_unittest.cc b/src/lib/dns/tests/tsig_unittest.cc index 7f6fa02bc8..c501f246f6 100644 --- a/src/lib/dns/tests/tsig_unittest.cc +++ b/src/lib/dns/tests/tsig_unittest.cc @@ -85,15 +85,15 @@ public: class TSIGTest : public ::testing::Test { protected: TSIGTest() : - tsig_ctx(NULL), qid(0x2d65), test_name("www.example.com"), + tsig_ctx(0), qid(0x2d65), test_name("www.example.com"), badkey_name("badkey.example.com"), test_class(RRClass::IN()), test_ttl(86400), message(Message::RENDER), dummy_data(1024, 0xdd), // should be sufficiently large for all tests dummy_record(badkey_name, TSIG(TSIGKey::HMACMD5_NAME(), 0x4da8877a, - TSIGContext::DEFAULT_FUDGE, 0, NULL, qid, 0, 0, NULL)) { + TSIGContext::DEFAULT_FUDGE, 0, 0, qid, 0, 0, 0)) { // Make sure we use the system time by default so that we won't be // confused due to other tests that tweak the time. - isc::util::detail::gettimeFunction = NULL; + isc::util::detail::gettimeFunction = 0; decodeBase64("SFuWd/q99SzF8Yzd1QbB9g==", secret); tsig_ctx.reset(new TestTSIGContext(TSIGKey(test_name, @@ -106,7 +106,7 @@ protected: secret.size()))); } ~TSIGTest() { - isc::util::detail::gettimeFunction = NULL; + isc::util::detail::gettimeFunction = 0; } // Many of the tests below create some DNS message and sign it under @@ -117,8 +117,8 @@ protected: unsigned int message_flags = RD_FLAG, RRType qtype = RRType::A(), - const char* answer_data = NULL, - const RRType* answer_type = NULL, + const char* answer_data = 0, + const RRType* answer_type = 0, bool add_question = true, Rcode rcode = Rcode::NOERROR()); @@ -168,8 +168,8 @@ TSIGTest::createMessageAndSign(uint16_t id, const Name& qname, if (add_question) { message.addQuestion(Question(qname, test_class, qtype)); } - if (answer_data != NULL) { - if (answer_type == NULL) { + if (answer_data) { + if (!answer_type) { answer_type = &qtype; } RRsetPtr answer_rrset(new RRset(qname, test_class, *answer_type, @@ -241,7 +241,7 @@ commonVerifyChecks(TSIGContext& ctx, const TSIGRecord* record, if (last_should_throw) { EXPECT_THROW(ctx.lastHadSignature(), TSIGContextError); } else { - EXPECT_EQ(record != NULL, ctx.lastHadSignature()); + EXPECT_EQ(record != 0, ctx.lastHadSignature()); } } @@ -266,7 +266,7 @@ TEST_F(TSIGTest, constructFromKeyRing) { // Add a matching key (we don't use the secret so leave it empty), and // construct it again. This time it should be constructed with a valid // key. - keyring.add(TSIGKey(test_name, TSIGKey::HMACMD5_NAME(), NULL, 0)); + keyring.add(TSIGKey(test_name, TSIGKey::HMACMD5_NAME(), 0, 0)); TSIGContext ctx2(test_name, TSIGKey::HMACMD5_NAME(), keyring); EXPECT_EQ(TSIGContext::INIT, ctx2.getState()); EXPECT_EQ(TSIGError::NOERROR(), ctx2.getError()); @@ -346,7 +346,7 @@ TEST_F(TSIGTest, signAtActualTime) { // Sign the message using the actual time, and check the accuracy of it. // We cannot reasonably predict the expected MAC, so don't bother to // check it. - const uint64_t now = static_cast<uint64_t>(time(NULL)); + const uint64_t now = static_cast<uint64_t>(time(0)); { SCOPED_TRACE("Sign test for query at actual time"); @@ -366,7 +366,7 @@ TEST_F(TSIGTest, signAtActualTime) { TEST_F(TSIGTest, signBadData) { // some specific bad data should be rejected proactively. const unsigned char dummy_data = 0; - EXPECT_THROW(tsig_ctx->sign(0, NULL, 10), InvalidParameter); + EXPECT_THROW(tsig_ctx->sign(0, 0, 10), InvalidParameter); EXPECT_THROW(tsig_ctx->sign(0, &dummy_data, 0), InvalidParameter); } @@ -380,8 +380,8 @@ TEST_F(TSIGTest, verifyBadData) { // Still nothing verified EXPECT_THROW(tsig_ctx->lastHadSignature(), TSIGContextError); - // And the data must not be NULL. - EXPECT_THROW(tsig_ctx->verify(&dummy_record, NULL, + // And the data must not be null. + EXPECT_THROW(tsig_ctx->verify(&dummy_record, 0, 12 + dummy_record.getLength()), InvalidParameter); @@ -449,7 +449,7 @@ TEST_F(TSIGTest, signUsingHMACSHA1) { SCOPED_TRACE("Sign test using HMAC-SHA1"); commonSignChecks(createMessageAndSign(sha1_qid, test_name, &sha1_ctx), sha1_qid, 0x4dae7d5f, expected_mac, - sizeof(expected_mac), 0, 0, NULL, + sizeof(expected_mac), 0, 0, 0, TSIGKey::HMACSHA1_NAME()); } } @@ -472,7 +472,7 @@ TEST_F(TSIGTest, signUsingHMACSHA224) { SCOPED_TRACE("Sign test using HMAC-SHA224"); commonSignChecks(createMessageAndSign(sha1_qid, test_name, &sha1_ctx), sha1_qid, 0x4dae7d5f, expected_mac, - sizeof(expected_mac), 0, 0, NULL, + sizeof(expected_mac), 0, 0, 0, TSIGKey::HMACSHA224_NAME()); } } @@ -651,7 +651,7 @@ TEST_F(TSIGTest, badtimeResponse) { // make and sign a response in the context of TSIG error. tsig = createMessageAndSign(test_qid, test_name, tsig_verify_ctx.get(), - QR_FLAG, RRType::SOA(), NULL, NULL, + QR_FLAG, RRType::SOA(), 0, 0, true, Rcode::NOTAUTH()); const uint8_t expected_otherdata[] = { 0, 0, 0x4d, 0xa8, 0xbe, 0x86 }; const uint8_t expected_mac[] = { @@ -748,7 +748,7 @@ TEST_F(TSIGTest, badsigResponse) { { SCOPED_TRACE("Sign test for response with BADSIG error"); commonSignChecks(createMessageAndSign(qid, test_name, &bad_ctx), - message.getQid(), 0x4da8877a, NULL, 0, + message.getQid(), 0x4da8877a, 0, 0, 16); // 16: BADSIG } } @@ -770,7 +770,7 @@ TEST_F(TSIGTest, badkeyResponse) { ConstTSIGRecordPtr sig = createMessageAndSign(qid, test_name, tsig_ctx.get()); EXPECT_EQ(badkey_name, sig->getName()); - commonSignChecks(sig, qid, 0x4da8877a, NULL, 0, 17); // 17: BADKEY + commonSignChecks(sig, qid, 0x4da8877a, 0, 0, 17); // 17: BADKEY } } @@ -788,7 +788,7 @@ TEST_F(TSIGTest, badkeyForResponse) { const TSIGRecord dummy_record2(test_name, TSIG(TSIGKey::HMACSHA1_NAME(), 0x4da8877a, TSIGContext::DEFAULT_FUDGE, - 0, NULL, qid, 0, 0, NULL)); + 0, 0, qid, 0, 0, 0)); { SCOPED_TRACE("Verify a response resulting in BADKEY due to bad alg"); commonVerifyChecks(*tsig_ctx, &dummy_record2, &dummy_data[0], @@ -833,7 +833,7 @@ TEST_F(TSIGTest, nosigThenValidate) { { SCOPED_TRACE("Verify a response without TSIG that should exist"); - commonVerifyChecks(*tsig_ctx, NULL, &dummy_data[0], + commonVerifyChecks(*tsig_ctx, 0, &dummy_data[0], dummy_data.size(), TSIGError::FORMERR(), TSIGContext::SENT_REQUEST, true); } @@ -1126,7 +1126,7 @@ TEST_F(TSIGTest, verifyMulti) { // internals here a little bit to generate correct test data tsig_ctx->update(renderer.getData(), renderer.getLength()); - commonVerifyChecks(*tsig_verify_ctx, NULL, + commonVerifyChecks(*tsig_verify_ctx, 0, renderer.getData(), renderer.getLength(), TSIGError(Rcode::NOERROR()), TSIGContext::VERIFIED_RESPONSE); @@ -1167,7 +1167,7 @@ TEST_F(TSIGTest, verifyMulti) { // 99 unsigned messages is OK. But the 100th must be signed, according // to the RFC2845, section 4.4 - commonVerifyChecks(*tsig_verify_ctx, NULL, + commonVerifyChecks(*tsig_verify_ctx, 0, renderer.getData(), renderer.getLength(), i == 99 ? TSIGError::FORMERR() : TSIGError(Rcode::NOERROR()), diff --git a/src/lib/dns/tests/tsigkey_unittest.cc b/src/lib/dns/tests/tsigkey_unittest.cc index 90c59ac112..40b573756a 100644 --- a/src/lib/dns/tests/tsigkey_unittest.cc +++ b/src/lib/dns/tests/tsigkey_unittest.cc @@ -44,24 +44,24 @@ TEST_F(TSIGKeyTest, algorithmNames) { // Also check conversion to cryptolink definitions EXPECT_EQ(isc::cryptolink::MD5, TSIGKey(key_name, TSIGKey::HMACMD5_NAME(), - NULL, 0).getAlgorithm()); + 0, 0).getAlgorithm()); EXPECT_EQ(isc::cryptolink::MD5, TSIGKey(key_name, TSIGKey::HMACMD5_SHORT_NAME(), - NULL, 0).getAlgorithm()); + 0, 0).getAlgorithm()); EXPECT_EQ(isc::cryptolink::SHA1, TSIGKey(key_name, TSIGKey::HMACSHA1_NAME(), - NULL, 0).getAlgorithm()); + 0, 0).getAlgorithm()); EXPECT_EQ(isc::cryptolink::SHA256, TSIGKey(key_name, TSIGKey::HMACSHA256_NAME(), - NULL, 0).getAlgorithm()); + 0, 0).getAlgorithm()); EXPECT_EQ(isc::cryptolink::SHA224, TSIGKey(key_name, TSIGKey::HMACSHA224_NAME(), - NULL, 0).getAlgorithm()); + 0, 0).getAlgorithm()); EXPECT_EQ(isc::cryptolink::SHA384, TSIGKey(key_name, TSIGKey::HMACSHA384_NAME(), - NULL, 0).getAlgorithm()); + 0, 0).getAlgorithm()); EXPECT_EQ(isc::cryptolink::SHA512, TSIGKey(key_name, TSIGKey::HMACSHA512_NAME(), - NULL, 0).getAlgorithm()); + 0, 0).getAlgorithm()); } TEST_F(TSIGKeyTest, construct) { @@ -84,7 +84,7 @@ TEST_F(TSIGKeyTest, construct) { EXPECT_THROW(TSIGKey(key_name, Name("unknown-alg"), secret.c_str(), secret.size()), isc::InvalidParameter); - TSIGKey key2(key_name, Name("unknown-alg"), NULL, 0); + TSIGKey key2(key_name, Name("unknown-alg"), 0, 0); EXPECT_EQ(key_name, key2.getKeyName()); EXPECT_EQ(Name("unknown-alg"), key2.getAlgorithmName()); @@ -109,11 +109,11 @@ TEST_F(TSIGKeyTest, construct) { // Invalid combinations of secret and secret_len: EXPECT_THROW(TSIGKey(key_name, TSIGKey::HMACSHA1_NAME(), secret.c_str(), 0), isc::InvalidParameter); - EXPECT_THROW(TSIGKey(key_name, TSIGKey::HMACSHA256_NAME(), NULL, 16), + EXPECT_THROW(TSIGKey(key_name, TSIGKey::HMACSHA256_NAME(), 0, 16), isc::InvalidParameter); // Empty secret - TSIGKey keye = TSIGKey(key_name, TSIGKey::HMACSHA256_NAME(), NULL, 0); + TSIGKey keye = TSIGKey(key_name, TSIGKey::HMACSHA256_NAME(), 0, 0); EXPECT_EQ(keye.getSecretLength(), 0); EXPECT_EQ(keye.getSecret(), (const void*)0); } @@ -248,8 +248,7 @@ TEST_F(TSIGKeyRingTest, removeFromSome) { TEST_F(TSIGKeyRingTest, find) { // If the keyring is empty the search should fail. EXPECT_EQ(TSIGKeyRing::NOTFOUND, keyring.find(key_name, md5_name).code); - EXPECT_EQ(static_cast<const TSIGKey*>(NULL), - keyring.find(key_name, md5_name).key); + EXPECT_FALSE(keyring.find(key_name, md5_name).key); // Add a key and try to find it. Should succeed. EXPECT_EQ(TSIGKeyRing::SUCCESS, keyring.add(TSIGKey(key_name, sha256_name, @@ -265,11 +264,11 @@ TEST_F(TSIGKeyRingTest, find) { const TSIGKeyRing::FindResult result2 = keyring.find(Name("different-key.example"), sha256_name); EXPECT_EQ(TSIGKeyRing::NOTFOUND, result2.code); - EXPECT_EQ(static_cast<const TSIGKey*>(NULL), result2.key); + EXPECT_FALSE(result2.key); const TSIGKeyRing::FindResult result3 = keyring.find(key_name, md5_name); EXPECT_EQ(TSIGKeyRing::NOTFOUND, result3.code); - EXPECT_EQ(static_cast<const TSIGKey*>(NULL), result3.key); + EXPECT_FALSE(result3.key); // But with just the name it should work const TSIGKeyRing::FindResult result4(keyring.find(key_name)); @@ -300,13 +299,11 @@ TEST_F(TSIGKeyRingTest, findFromSome) { EXPECT_EQ(TSIGKeyRing::NOTFOUND, keyring.find(Name("noexist.example"), sha1_name).code); - EXPECT_EQ(static_cast<const TSIGKey*>(NULL), - keyring.find(Name("noexist.example"), sha256_name).key); + EXPECT_FALSE(keyring.find(Name("noexist.example"), sha256_name).key); EXPECT_EQ(TSIGKeyRing::NOTFOUND, keyring.find(Name("another.example"), sha1_name).code); - EXPECT_EQ(static_cast<const TSIGKey*>(NULL), - keyring.find(Name("another.example"), sha256_name).key); + EXPECT_FALSE(keyring.find(Name("another.example"), sha256_name).key); } TEST(TSIGStringTest, TSIGKeyFromToString) { @@ -314,7 +311,7 @@ TEST(TSIGStringTest, TSIGKeyFromToString) { TSIGKey k2 = TSIGKey("test.example.:MSG6Ng==:hmac-md5.sig-alg.reg.int."); TSIGKey k3 = TSIGKey("test.example:MSG6Ng=="); TSIGKey k4 = TSIGKey("test.example.:MSG6Ng==:hmac-md5.sig-alg.reg.int.:120"); - TSIGKey k5 = TSIGKey(Name("test.example."), Name("hmac-sha1."), NULL, 0); + TSIGKey k5 = TSIGKey(Name("test.example."), Name("hmac-sha1."), 0, 0); // "Unknown" key with empty secret is okay TSIGKey k6 = TSIGKey("test.example.::unknown"); diff --git a/src/lib/dns/tests/tsigrecord_unittest.cc b/src/lib/dns/tests/tsigrecord_unittest.cc index 624f03b85e..3468d62716 100644 --- a/src/lib/dns/tests/tsigrecord_unittest.cc +++ b/src/lib/dns/tests/tsigrecord_unittest.cc @@ -39,7 +39,7 @@ protected: TSIGRecordTest() : test_name("www.example.com"), test_mac(16, 0xda), test_rdata(TSIG(TSIGKey::HMACMD5_NAME(), 0x4da8877a, TSIGContext::DEFAULT_FUDGE, - test_mac.size(), &test_mac[0], 0x2d65, 0, 0, NULL)), + test_mac.size(), &test_mac[0], 0x2d65, 0, 0, 0)), test_record(test_name, test_rdata), buffer(0) { } diff --git a/src/lib/dns/tsig.cc b/src/lib/dns/tsig.cc index e85d636670..9cbb458bdf 100644 --- a/src/lib/dns/tsig.cc +++ b/src/lib/dns/tsig.cc @@ -101,7 +101,7 @@ struct TSIGContext::TSIGContextImpl { } else if (state_ == SENT_REQUEST && error == TSIGError::NOERROR()) { state_ = VERIFIED_RESPONSE; } - if (digest != NULL) { + if (digest) { previous_digest_.assign(static_cast<const uint8_t*>(digest), static_cast<const uint8_t*>(digest) + digest_len); @@ -265,7 +265,7 @@ TSIGContext::TSIGContext(const TSIGKey& key) : impl_(new TSIGContextImpl(key)) { } TSIGContext::TSIGContext(const Name& key_name, const Name& algorithm_name, - const TSIGKeyRing& keyring) : impl_(NULL) { + const TSIGKeyRing& keyring) : impl_(0) { const TSIGKeyRing::FindResult result(keyring.find(key_name, algorithm_name)); if (result.code == TSIGKeyRing::NOTFOUND) { @@ -273,8 +273,8 @@ TSIGContext::TSIGContext(const Name& key_name, const Name& algorithm_name, // parameters and empty secret. In the common scenario this will // be used in subsequent response with a TSIG indicating a BADKEY // error. - impl_.reset(new TSIGContextImpl(TSIGKey(key_name, algorithm_name, - NULL, 0), TSIGError::BAD_KEY())); + impl_.reset(new TSIGContextImpl(TSIGKey(key_name, algorithm_name, 0, 0), + TSIGError::BAD_KEY())); } else { impl_.reset(new TSIGContextImpl(*result.key)); } @@ -340,7 +340,7 @@ TSIGContext::sign(const uint16_t qid, const void* const data, "TSIG sign attempt after verifying a response"); } - if (data == NULL || data_len == 0) { + if (!data || data_len == 0) { isc_throw(InvalidParameter, "TSIG sign error: empty data is given"); } @@ -358,8 +358,8 @@ TSIGContext::sign(const uint16_t qid, const void* const data, ConstTSIGRecordPtr tsig(new TSIGRecord( impl_->key_.getKeyName(), any::TSIG(impl_->key_.getAlgorithmName(), - now, DEFAULT_FUDGE, 0, NULL, - qid, error.getCode(), 0, NULL))); + now, DEFAULT_FUDGE, 0, 0, + qid, error.getCode(), 0, 0))); impl_->previous_digest_.clear(); impl_->state_ = SENT_RESPONSE; return (tsig); @@ -389,7 +389,7 @@ TSIGContext::sign(const uint16_t qid, const void* const data, otherdatabuf.writeUint32(now & 0xffffffff); } const void* const otherdata = - (otherlen == 0) ? NULL : otherdatabuf.getData(); + (otherlen == 0) ? 0 : otherdatabuf.getData(); // Then calculate the digest. If state_ is SENT_RESPONSE we are sending // a continued message in the same TCP stream so skip digesting // variables except for time related variables (RFC2845 4.4). @@ -423,7 +423,7 @@ TSIGContext::verify(const TSIGRecord* const record, const void* const data, "TSIG verify attempt after sending a response"); } - if (record == NULL) { + if (!record) { if (impl_->last_sig_dist_ >= 0 && impl_->last_sig_dist_ < 99) { // It is not signed, but in the middle of TCP stream. We just // update the HMAC state and consider this message OK. @@ -432,13 +432,13 @@ TSIGContext::verify(const TSIGRecord* const record, const void* const data, // now. impl_->last_sig_dist_++; // No digest to return now. Just say it's OK. - return (impl_->postVerifyUpdate(TSIGError::NOERROR(), NULL, 0)); + return (impl_->postVerifyUpdate(TSIGError::NOERROR(), 0, 0)); } // This case happens when we sent a signed request and have received an // unsigned response. According to RFC2845 Section 4.6 this case should be // considered a "format error" (although the specific error code // wouldn't matter much for the caller). - return (impl_->postVerifyUpdate(TSIGError::FORMERR(), NULL, 0)); + return (impl_->postVerifyUpdate(TSIGError::FORMERR(), 0, 0)); } const any::TSIG& tsig_rdata = record->getRdata(); @@ -448,7 +448,7 @@ TSIGContext::verify(const TSIGRecord* const record, const void* const data, isc_throw(InvalidParameter, "TSIG verify: data length is invalid: " << data_len); } - if (data == NULL) { + if (!data) { isc_throw(InvalidParameter, "TSIG verify: empty data is invalid"); } @@ -459,11 +459,11 @@ TSIGContext::verify(const TSIGRecord* const record, const void* const data, // it using the consistent key in the context. If the check fails we are // done with BADKEY. if (impl_->state_ == INIT && impl_->error_ == TSIGError::BAD_KEY()) { - return (impl_->postVerifyUpdate(TSIGError::BAD_KEY(), NULL, 0)); + return (impl_->postVerifyUpdate(TSIGError::BAD_KEY(), 0, 0)); } if (impl_->key_.getKeyName() != record->getName() || impl_->key_.getAlgorithmName() != tsig_rdata.getAlgorithm()) { - return (impl_->postVerifyUpdate(TSIGError::BAD_KEY(), NULL, 0)); + return (impl_->postVerifyUpdate(TSIGError::BAD_KEY(), 0, 0)); } // Check time: the current time must be in the range of @@ -476,7 +476,7 @@ TSIGContext::verify(const TSIGRecord* const record, const void* const data, const uint64_t now = getTSIGTime(); if (tsig_rdata.getTimeSigned() + DEFAULT_FUDGE < now || tsig_rdata.getTimeSigned() - DEFAULT_FUDGE > now) { - const void* digest = NULL; + const void* digest = 0; size_t digest_len = 0; if (impl_->state_ == INIT) { digest = tsig_rdata.getMAC(); @@ -497,7 +497,7 @@ TSIGContext::verify(const TSIGRecord* const record, const void* const data, if (error != TSIGError::BAD_SIG() && error != TSIGError::BAD_KEY()) { error = TSIGError::BAD_SIG(); } - return (impl_->postVerifyUpdate(error, NULL, 0)); + return (impl_->postVerifyUpdate(error, 0, 0)); } HMACPtr hmac(impl_->createHMAC()); @@ -511,16 +511,16 @@ TSIGContext::verify(const TSIGRecord* const record, const void* const data, // Signature length check based on RFC 4635 3.1 if (tsig_rdata.getMACSize() > hmac->getOutputLength()) { // signature length too big - return (impl_->postVerifyUpdate(TSIGError::FORMERR(), NULL, 0)); + return (impl_->postVerifyUpdate(TSIGError::FORMERR(), 0, 0)); } if ((tsig_rdata.getMACSize() < 10) || (tsig_rdata.getMACSize() < (hmac->getOutputLength() / 2))) { // signature length below minimum - return (impl_->postVerifyUpdate(TSIGError::FORMERR(), NULL, 0)); + return (impl_->postVerifyUpdate(TSIGError::FORMERR(), 0, 0)); } if (tsig_rdata.getMACSize() < impl_->digest_len_) { // (truncated) signature length too small - return (impl_->postVerifyUpdate(TSIGError::BAD_TRUNC(), NULL, 0)); + return (impl_->postVerifyUpdate(TSIGError::BAD_TRUNC(), 0, 0)); } // @@ -551,7 +551,7 @@ TSIGContext::verify(const TSIGRecord* const record, const void* const data, tsig_rdata.getMACSize())); } - return (impl_->postVerifyUpdate(TSIGError::BAD_SIG(), NULL, 0)); + return (impl_->postVerifyUpdate(TSIGError::BAD_SIG(), 0, 0)); } bool diff --git a/src/lib/dns/tsigkey.cc b/src/lib/dns/tsigkey.cc index a29c1db581..92a12bd146 100644 --- a/src/lib/dns/tsigkey.cc +++ b/src/lib/dns/tsigkey.cc @@ -94,10 +94,10 @@ TSIGKey::TSIGKeyImpl { TSIGKey::TSIGKey(const Name& key_name, const Name& algorithm_name, const void* secret, size_t secret_len, - size_t digestbits /*= 0*/) : impl_(NULL) { + size_t digestbits /*= 0*/) : impl_(0) { const HashAlgorithm algorithm = convertAlgorithmName(algorithm_name); - if ((secret != NULL && secret_len == 0) || - (secret == NULL && secret_len != 0)) { + if ((secret && secret_len == 0) || + (!secret && secret_len != 0)) { isc_throw(InvalidParameter, "TSIGKey secret and its length are inconsistent: " << key_name << ":" << algorithm_name); @@ -107,7 +107,7 @@ TSIGKey::TSIGKey(const Name& key_name, const Name& algorithm_name, "TSIGKey with unknown algorithm has non empty secret: " << key_name << ":" << algorithm_name); } - if (secret == NULL) { + if (!secret) { impl_.reset(new TSIGKey::TSIGKeyImpl(key_name, algorithm_name, algorithm, digestbits)); } else { @@ -116,7 +116,7 @@ TSIGKey::TSIGKey(const Name& key_name, const Name& algorithm_name, } } -TSIGKey::TSIGKey(const std::string& str) : impl_(NULL) { +TSIGKey::TSIGKey(const std::string& str) : impl_(0) { try { istringstream iss(str); @@ -222,7 +222,7 @@ TSIGKey::getDigestbits() const { const void* TSIGKey::getSecret() const { - return ((impl_->secret_.size() > 0) ? &impl_->secret_[0] : NULL); + return ((impl_->secret_.size() > 0) ? &impl_->secret_[0] : 0); } size_t @@ -334,7 +334,7 @@ TSIGKeyRing::find(const Name& key_name) const { TSIGKeyRingImpl::TSIGKeyMap::const_iterator found = impl_->keys.find(key_name); if (found == impl_->keys.end()) { - return (FindResult(NOTFOUND, NULL)); + return (FindResult(NOTFOUND, 0)); } return (FindResult(SUCCESS, &((*found).second))); } @@ -345,7 +345,7 @@ TSIGKeyRing::find(const Name& key_name, const Name& algorithm_name) const { impl_->keys.find(key_name); if (found == impl_->keys.end() || (*found).second.getAlgorithmName() != algorithm_name) { - return (FindResult(NOTFOUND, NULL)); + return (FindResult(NOTFOUND, 0)); } return (FindResult(SUCCESS, &((*found).second))); } diff --git a/src/lib/dns/tsigkey.h b/src/lib/dns/tsigkey.h index c9850b08cb..44daf57666 100644 --- a/src/lib/dns/tsigkey.h +++ b/src/lib/dns/tsigkey.h @@ -66,7 +66,7 @@ public: /// <code>static const</code> member functions. /// /// Other names are still accepted as long as the secret is empty - /// (\c secret is \c NULL and \c secret_len is 0), however; in some cases + /// (\c secret is null and \c secret_len is 0), however; in some cases /// we might want to treat just the pair of key name and algorithm name /// opaquely, e.g., when generating a response TSIG with a BADKEY error /// because the algorithm is unknown as specified in Section 3.2 of @@ -87,7 +87,7 @@ public: /// specified, an exception of type \c InvalidParameter will be thrown. /// /// \c secret and \c secret_len must be consistent in that the latter - /// is 0 if and only if the former is \c NULL; + /// is 0 if and only if the former is null; /// otherwise an exception of type \c InvalidParameter will be thrown. /// /// \c digestbits is the truncated length in bits or 0 which means no @@ -104,7 +104,7 @@ public: /// form of domain name. For example, it can be /// \c TSIGKey::HMACSHA256_NAME() for HMAC-SHA256. /// \param secret Point to a binary sequence of the shared secret to be - /// used for this key, or \c NULL if the secret is empty. + /// used for this key, or null if the secret is empty. /// \param secret_len The size of the binary %data (\c secret) in bytes. /// \param digestbits The number of bits to include in the digest /// (0 means to include all) @@ -179,7 +179,7 @@ public: /// Return the value of the TSIG secret. /// - /// If it returns a non NULL pointer, the memory region beginning at the + /// If it returns a non null pointer, the memory region beginning at the /// address returned by this method is valid up to the bytes specified /// by the return value of \c getSecretLength(). /// @@ -259,7 +259,7 @@ public: /// to the found key to represent the result of \c find(). /// We use this in order to avoid overloading the return value for both /// the result code ("success" or "not found") and the found object, - /// i.e., avoid using \c NULL to mean "not found", etc. + /// i.e., avoid using null to mean "not found", etc. /// /// This is a simple value class with no internal state, so for /// convenience we allow the applications to refer to the members @@ -341,7 +341,7 @@ public: /// object as follows: /// - \c code: \c SUCCESS if a key is found; otherwise \c NOTFOUND. /// - \c key: A pointer to the found \c TSIGKey object if one is found; - /// otherwise \c NULL. + /// otherwise null. /// /// The pointer returned in the \c FindResult object is only valid until /// the corresponding key is removed from the key ring. @@ -363,7 +363,7 @@ public: /// object as follows: /// - \c code: \c SUCCESS if a key is found; otherwise \c NOTFOUND. /// - \c key: A pointer to the found \c TSIGKey object if one is found; - /// otherwise \c NULL. + /// otherwise null. /// /// The pointer returned in the \c FindResult object is only valid until /// the corresponding key is removed from the key ring. |