diff --git a/src/Anon.cc b/src/Anon.cc index 4c54510217..41544ab8c8 100644 --- a/src/Anon.cc +++ b/src/Anon.cc @@ -12,7 +12,7 @@ #include "Reporter.h" -AnonymizeIPAddr* ip_anonymizer[NUM_ADDR_ANONYMIZATION_METHODS] = {0}; +AnonymizeIPAddr* ip_anonymizer[NUM_ADDR_ANONYMIZATION_METHODS] = {nullptr}; static uint32_t rand32() { @@ -148,7 +148,7 @@ AnonymizeIPAddr_A50::~AnonymizeIPAddr_A50() void AnonymizeIPAddr_A50::init() { - root = next_free_node = 0; + root = next_free_node = nullptr; // Prepare special nodes for 0.0.0.0 and 255.255.255.255. memset(&special_nodes[0], 0, sizeof(special_nodes)); @@ -222,7 +222,7 @@ AnonymizeIPAddr_A50::Node* AnonymizeIPAddr_A50::new_node_block() for ( int i = 1; i < block_size - 1; ++i ) block[i].child[0] = &block[i+1]; - block[block_size - 1].child[0] = 0; + block[block_size - 1].child[0] = nullptr; next_free_node = &block[1]; return &block[0]; @@ -276,12 +276,12 @@ AnonymizeIPAddr_A50::Node* AnonymizeIPAddr_A50::make_peer(ipaddr32_t a, Node* n) Node* down[2]; if ( ! (down[0] = new_node()) ) - return 0; + return nullptr; if ( ! (down[1] = new_node()) ) { free_node(down[0]); - return 0; + return nullptr; } // swivel is first bit 'a' and 'old->input' differ. @@ -292,7 +292,7 @@ AnonymizeIPAddr_A50::Node* AnonymizeIPAddr_A50::make_peer(ipaddr32_t a, Node* n) down[bitvalue]->input = a; down[bitvalue]->output = make_output(n->output, swivel); - down[bitvalue]->child[0] = down[bitvalue]->child[1] = 0; + down[bitvalue]->child[0] = down[bitvalue]->child[1] = nullptr; *down[1 - bitvalue] = *n; // copy orig node down one level @@ -316,7 +316,7 @@ AnonymizeIPAddr_A50::Node* AnonymizeIPAddr_A50::find_node(ipaddr32_t a) root = new_node(); root->input = a; root->output = rand32(); - root->child[0] = root->child[1] = 0; + root->child[0] = root->child[1] = nullptr; return root; } @@ -351,12 +351,12 @@ AnonymizeIPAddr_A50::Node* AnonymizeIPAddr_A50::find_node(ipaddr32_t a) } reporter->InternalError("out of memory!"); - return 0; + return nullptr; } void init_ip_addr_anonymizers() { - ip_anonymizer[KEEP_ORIG_ADDR] = 0; + ip_anonymizer[KEEP_ORIG_ADDR] = nullptr; ip_anonymizer[SEQUENTIALLY_NUMBERED] = new AnonymizeIPAddr_Seq(); ip_anonymizer[RANDOM_MD5] = new AnonymizeIPAddr_RandomMD5(); ip_anonymizer[PREFIX_PRESERVING_A50] = new AnonymizeIPAddr_A50(); @@ -365,7 +365,7 @@ void init_ip_addr_anonymizers() ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl) { - TableVal* preserve_addr = 0; + TableVal* preserve_addr = nullptr; AddrVal addr(ip); int method = -1; diff --git a/src/Attr.cc b/src/Attr.cc index ea735b67f0..bf39c7f9c9 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -197,7 +197,7 @@ void Attributes::AddAttrs(Attributes* a) Attr* Attributes::FindAttr(attr_tag t) const { if ( ! attrs ) - return 0; + return nullptr; for ( const auto& a : *attrs ) { @@ -205,7 +205,7 @@ Attr* Attributes::FindAttr(attr_tag t) const return a; } - return 0; + return nullptr; } void Attributes::RemoveAttr(attr_tag t) diff --git a/src/Base64.cc b/src/Base64.cc index 51d2b707ad..16e43d296c 100644 --- a/src/Base64.cc +++ b/src/Base64.cc @@ -55,7 +55,7 @@ int* Base64Converter::InitBase64Table(const string& alphabet) if ( alphabet == default_alphabet && default_table_initialized ) return default_base64_table; - int* base64_table = 0; + int* base64_table = nullptr; if ( alphabet == default_alphabet ) { @@ -98,7 +98,7 @@ Base64Converter::Base64Converter(Connection* arg_conn, const string& arg_alphabe alphabet = default_alphabet; } - base64_table = 0; + base64_table = nullptr; base64_group_next = 0; base64_padding = base64_after_padding = 0; errored = 0; @@ -234,7 +234,7 @@ BroString* decode_base64(const BroString* s, const BroString* a, Connection* con { reporter->Error("base64 decoding alphabet is not 64 characters: %s", a->CheckString()); - return 0; + return nullptr; } int buf_len = int((s->Len() + 3) / 4) * 3 + 1; @@ -259,7 +259,7 @@ BroString* decode_base64(const BroString* s, const BroString* a, Connection* con err: delete [] rbuf; - return 0; + return nullptr; } BroString* encode_base64(const BroString* s, const BroString* a, Connection* conn) @@ -268,10 +268,10 @@ BroString* encode_base64(const BroString* s, const BroString* a, Connection* con { reporter->Error("base64 alphabet is not 64 characters: %s", a->CheckString()); - return 0; + return nullptr; } - char* outbuf = 0; + char* outbuf = nullptr; int outlen = 0; Base64Converter enc(conn, a ? a->CheckString() : ""); enc.Encode(s->Len(), (const unsigned char*) s->Bytes(), &outlen, &outbuf); diff --git a/src/Base64.h b/src/Base64.h index cdebc93017..2348eccc11 100644 --- a/src/Base64.h +++ b/src/Base64.h @@ -59,5 +59,5 @@ protected: }; -BroString* decode_base64(const BroString* s, const BroString* a = 0, Connection* conn = 0); -BroString* encode_base64(const BroString* s, const BroString* a = 0, Connection* conn = 0); +BroString* decode_base64(const BroString* s, const BroString* a = nullptr, Connection* conn = nullptr); +BroString* encode_base64(const BroString* s, const BroString* a = nullptr, Connection* conn = nullptr); diff --git a/src/BroString.cc b/src/BroString.cc index 33a14a315b..cfd7e92c15 100644 --- a/src/BroString.cc +++ b/src/BroString.cc @@ -284,7 +284,7 @@ BroString* BroString::GetSubstring(int start, int len) const { // This code used to live in zeek.bif's sub_bytes() routine. if ( start < 0 || start > n ) - return 0; + return nullptr; if ( len < 0 || len > n - start ) len = n - start; @@ -302,7 +302,7 @@ BroString::Vec* BroString::Split(const BroString::IdxVec& indices) const unsigned int i; if ( indices.empty() ) - return 0; + return nullptr; // Copy input, ensuring space for "0": IdxVec idx(1 + indices.size()); @@ -343,7 +343,7 @@ VectorVal* BroString:: VecToPolicy(Vec* vec) VectorVal* result = new VectorVal(internal_type("string_vec")->AsVectorType()); if ( ! result ) - return 0; + return nullptr; for ( unsigned int i = 0; i < vec->size(); ++i ) { diff --git a/src/BroString.h b/src/BroString.h index 40a1029291..66c3bce4b7 100644 --- a/src/BroString.h +++ b/src/BroString.h @@ -94,7 +94,7 @@ public: // // Note that you need to delete[] the resulting string. // - char* Render(int format = EXPANDED_STRING, int* len = 0) const; + char* Render(int format = EXPANDED_STRING, int* len = nullptr) const; // Similar to the above, but useful for output streams. // Also more useful for debugging purposes since no deallocation diff --git a/src/Brofiler.cc b/src/Brofiler.cc index c406182747..a2391145cd 100644 --- a/src/Brofiler.cc +++ b/src/Brofiler.cc @@ -76,7 +76,7 @@ bool Brofiler::ReadStats() pair location_desc(std::move(location), std::move(desc)); uint64_t count; - atoi_n(cnt.size(), cnt.c_str(), 0, 10, count); + atoi_n(cnt.size(), cnt.c_str(), nullptr, 10, count); usage_map.emplace(std::move(location_desc), count); } diff --git a/src/CompHash.cc b/src/CompHash.cc index b28c9e307b..7d9a29da62 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -47,19 +47,19 @@ CompositeHash::CompositeHash(IntrusivePtr composite_type) // via the singleton later. singleton_tag = (*type->Types())[0]->InternalType(); size = 0; - key = 0; + key = nullptr; } else { - size = ComputeKeySize(0, true, true); + size = ComputeKeySize(nullptr, true, true); if ( size > 0 ) // Fixed size. Make sure what we get is fully aligned. key = reinterpret_cast (new double[size/sizeof(double) + 1]); else - key = 0; + key = nullptr; } } @@ -72,7 +72,7 @@ CompositeHash::~CompositeHash() char* CompositeHash::SingleValHash(bool type_check, char* kp0, BroType* bt, Val* v, bool optional) const { - char* kp1 = 0; + char* kp1 = nullptr; InternalTypeTag t = bt->InternalType(); if ( optional ) @@ -90,7 +90,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, { InternalTypeTag vt = v->Type()->InternalType(); if ( vt != t ) - return 0; + return nullptr; } switch ( t ) { @@ -186,12 +186,12 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, bool optional = (a && a->FindAttr(ATTR_OPTIONAL)); if ( ! (rv_i || optional) ) - return 0; + return nullptr; if ( ! (kp = SingleValHash(type_check, kp, rt->FieldType(i), rv_i, optional)) ) - return 0; + return nullptr; } kp1 = kp; @@ -242,7 +242,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, if ( ! (kp1 = SingleValHash(type_check, kp1, key->Type(), key, false)) ) - return 0; + return nullptr; if ( ! v->Type()->IsSet() ) { @@ -250,7 +250,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, if ( ! (kp1 = SingleValHash(type_check, kp1, val->Type(), val.get(), false)) ) - return 0; + return nullptr; } } @@ -278,7 +278,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, { if ( ! (kp1 = SingleValHash(type_check, kp1, vt->YieldType(), val, false)) ) - return 0; + return nullptr; } } } @@ -295,7 +295,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, Val* v = lv->Index(i); if ( ! (kp1 = SingleValHash(type_check, kp1, v->Type(), v, false)) ) - return 0; + return nullptr; } } break; @@ -303,7 +303,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, default: { reporter->InternalError("bad index type in CompositeHash::SingleValHash"); - return 0; + return nullptr; } } @@ -326,7 +326,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, break; case TYPE_INTERNAL_ERROR: - return 0; + return nullptr; } return kp1; @@ -361,7 +361,7 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const { int sz = ComputeKeySize(v, type_check, false); if ( sz == 0 ) - return 0; + return nullptr; k = reinterpret_cast(new double[sz/sizeof(double) + 1]); type_check = false; // no need to type-check again. @@ -370,18 +370,18 @@ HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const const type_list* tl = type->Types(); if ( type_check && v->Type()->Tag() != TYPE_LIST ) - return 0; + return nullptr; const val_list* vl = v->AsListVal()->Vals(); if ( type_check && vl->length() != tl->length() ) - return 0; + return nullptr; char* kp = k; loop_over_list(*tl, i) { kp = SingleValHash(type_check, kp, (*tl)[i], (*vl)[i], false); if ( ! kp ) - return 0; + return nullptr; } return new HashKey((k == key), (void*) k, kp - k); @@ -393,13 +393,13 @@ HashKey* CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) cons { const val_list* vl = v->AsListVal()->Vals(); if ( type_check && vl->length() != 1 ) - return 0; + return nullptr; v = (*vl)[0]; } if ( type_check && v->Type()->InternalType() != singleton_tag ) - return 0; + return nullptr; switch ( singleton_tag ) { case TYPE_INTERNAL_INT: @@ -434,17 +434,17 @@ HashKey* CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) cons } reporter->InternalError("bad index type in CompositeHash::ComputeSingletonHash"); - return 0; + return nullptr; case TYPE_INTERNAL_STRING: return new HashKey(v->AsString()); case TYPE_INTERNAL_ERROR: - return 0; + return nullptr; default: reporter->InternalError("bad internal type in CompositeHash::ComputeSingletonHash"); - return 0; + return nullptr; } } @@ -507,7 +507,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, case TYPE_RECORD: { - const RecordVal* rv = v ? v->AsRecordVal() : 0; + const RecordVal* rv = v ? v->AsRecordVal() : nullptr; RecordType* rt = bt->AsRecordType(); int num_fields = rt->NumFields(); @@ -517,7 +517,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, bool optional = (a && a->FindAttr(ATTR_OPTIONAL)); sz = SingleTypeKeySize(rt->FieldType(i), - rv ? rv->Lookup(i) : 0, + rv ? rv->Lookup(i) : nullptr, type_check, sz, optional, calc_static_size); if ( ! sz ) @@ -632,7 +632,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, int CompositeHash::ComputeKeySize(const Val* v, bool type_check, bool calc_static_size) const { const type_list* tl = type->Types(); - const val_list* vl = 0; + const val_list* vl = nullptr; if ( v ) { if ( type_check && v->Type()->Tag() != TYPE_LIST ) @@ -646,7 +646,7 @@ int CompositeHash::ComputeKeySize(const Val* v, bool type_check, bool calc_stati int sz = 0; loop_over_list(*tl, i) { - sz = SingleTypeKeySize((*tl)[i], v ? v->AsListVal()->Index(i) : 0, + sz = SingleTypeKeySize((*tl)[i], v ? v->AsListVal()->Index(i) : nullptr, type_check, sz, false, calc_static_size); if ( ! sz ) return 0; @@ -745,7 +745,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, TypeTag tag = t->Tag(); InternalTypeTag it = t->InternalType(); - const char* kp1 = 0; + const char* kp1 = nullptr; if ( optional ) { diff --git a/src/Conn.cc b/src/Conn.cc index bc37dea87a..95ee5af8f2 100644 --- a/src/Conn.cc +++ b/src/Conn.cc @@ -120,7 +120,7 @@ Connection::Connection(NetSessions* s, const ConnIDKey& k, double t, const ConnI if ( arg_encap ) encapsulation = new EncapsulationStack(*arg_encap); else - encapsulation = 0; + encapsulation = nullptr; } Connection::~Connection() @@ -132,7 +132,7 @@ Connection::~Connection() if ( conn_val ) { - conn_val->SetOrigin(0); + conn_val->SetOrigin(nullptr); Unref(conn_val); } @@ -148,7 +148,7 @@ void Connection::CheckEncapsulation(const EncapsulationStack* arg_encap) { if ( *encapsulation != *arg_encap ) { - Event(tunnel_changed, 0, arg_encap->GetVectorVal()); + Event(tunnel_changed, nullptr, arg_encap->GetVectorVal()); delete encapsulation; encapsulation = new EncapsulationStack(*arg_encap); } @@ -157,14 +157,14 @@ void Connection::CheckEncapsulation(const EncapsulationStack* arg_encap) else if ( encapsulation ) { EncapsulationStack empty; - Event(tunnel_changed, 0, empty.GetVectorVal()); + Event(tunnel_changed, nullptr, empty.GetVectorVal()); delete encapsulation; encapsulation = nullptr; } else if ( arg_encap ) { - Event(tunnel_changed, 0, arg_encap->GetVectorVal()); + Event(tunnel_changed, nullptr, arg_encap->GetVectorVal()); encapsulation = new EncapsulationStack(*arg_encap); } } @@ -269,7 +269,7 @@ void Connection::HistoryThresholdEvent(EventHandlerPtr e, bool is_orig, void Connection::DeleteTimer(double /* t */) { if ( is_active ) - Event(connection_timeout, 0); + Event(connection_timeout, nullptr); sessions->Remove(this); } @@ -282,7 +282,7 @@ void Connection::InactivityTimer(double t) { if ( last_time + inactivity_timeout <= t ) { - Event(connection_timeout, 0); + Event(connection_timeout, nullptr); sessions->Remove(this); ++killed_by_inactivity; } @@ -402,12 +402,12 @@ RecordVal* Connection::BuildConnVal() analyzer::Analyzer* Connection::FindAnalyzer(analyzer::ID id) { - return root_analyzer ? root_analyzer->FindChild(id) : 0; + return root_analyzer ? root_analyzer->FindChild(id) : nullptr; } analyzer::Analyzer* Connection::FindAnalyzer(const analyzer::Tag& tag) { - return root_analyzer ? root_analyzer->FindChild(tag) : 0; + return root_analyzer ? root_analyzer->FindChild(tag) : nullptr; } analyzer::Analyzer* Connection::FindAnalyzer(const char* name) @@ -696,7 +696,7 @@ void Connection::CheckFlowLabel(bool is_orig, uint32_t flow_label) if ( connection_flow_label_changed && (is_orig ? saw_first_orig_packet : saw_first_resp_packet) ) { - EnqueueEvent(connection_flow_label_changed, 0, + EnqueueEvent(connection_flow_label_changed, nullptr, IntrusivePtr{AdoptRef{}, BuildConnVal()}, IntrusivePtr{AdoptRef{}, val_mgr->GetBool(is_orig)}, IntrusivePtr{AdoptRef{}, val_mgr->GetCount(my_flow_label)}, diff --git a/src/Conn.h b/src/Conn.h index a2bb1face5..5048a98f0f 100644 --- a/src/Conn.h +++ b/src/Conn.h @@ -180,13 +180,13 @@ public: // given that event's first argument will be it, and it's second will be // the connection value. If 'name' is null, then the event's first // argument is the connection value. - void Event(EventHandlerPtr f, analyzer::Analyzer* analyzer, const char* name = 0); + void Event(EventHandlerPtr f, analyzer::Analyzer* analyzer, const char* name = nullptr); // If a handler exists for 'f', an event will be generated. In any case, // 'v1' and 'v2' reference counts get decremented. The event's first // argument is the connection value, second argument is 'v1', and if 'v2' // is given that will be it's third argument. - void Event(EventHandlerPtr f, analyzer::Analyzer* analyzer, Val* v1, Val* v2 = 0); + void Event(EventHandlerPtr f, analyzer::Analyzer* analyzer, Val* v1, Val* v2 = nullptr); // If a handler exists for 'f', an event will be generated. In any case, // reference count for each element in the 'vl' list are decremented. The diff --git a/src/DFA.cc b/src/DFA.cc index e99e772fcc..071a8f9570 100644 --- a/src/DFA.cc +++ b/src/DFA.cc @@ -17,7 +17,7 @@ DFA_State::DFA_State(int arg_state_num, const EquivClass* ec, num_sym = ec->NumClasses(); nfa_states = arg_nfa_states; accept = arg_accept; - mark = 0; + mark = nullptr; SymPartition(ec); @@ -96,7 +96,7 @@ DFA_State* DFA_State::ComputeXtion(int sym, DFA_Machine* machine) else { delete ns; - next_d = 0; // Jam + next_d = nullptr; // Jam } AddXtion(equiv_sym, next_d); @@ -182,7 +182,7 @@ void DFA_State::ClearMarks() { if ( mark ) { - SetMark(0); + SetMark(nullptr); for ( int i = 0; i < num_sym; ++i ) { @@ -395,7 +395,7 @@ DFA_Machine::DFA_Machine(NFA_Machine* n, EquivClass* arg_ec) } else { - start_state = 0; // Jam + start_state = nullptr; // Jam delete ns; } } @@ -451,7 +451,7 @@ bool DFA_Machine::StateSetToDFA_State(NFA_state_list* state_set, if ( accept->empty() ) { delete accept; - accept = 0; + accept = nullptr; } DFA_State* ds = new DFA_State(state_count++, ec, state_set, accept); diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index e0bc8ffe90..b39ba83aab 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -194,7 +194,7 @@ DNS_Mapping::DNS_Mapping(const IPAddr& addr, struct hostent* h, uint32_t ttl) { Init(h); req_addr = addr; - req_host = 0; + req_host = nullptr; req_ttl = ttl; } @@ -203,7 +203,7 @@ DNS_Mapping::DNS_Mapping(FILE* f) Clear(); init_failed = true; - req_host = 0; + req_host = nullptr; req_ttl = 0; creation_time = 0; @@ -255,7 +255,7 @@ DNS_Mapping::DNS_Mapping(FILE* f) } } else - addrs = 0; + addrs = nullptr; init_failed = false; } @@ -302,7 +302,7 @@ IntrusivePtr DNS_Mapping::AddrsSet() { IntrusivePtr DNS_Mapping::Host() { if ( failed || num_names == 0 || ! names[0] ) - return 0; + return nullptr; if ( ! host_val ) host_val = make_intrusive(names[0]); @@ -315,8 +315,8 @@ void DNS_Mapping::Init(struct hostent* h) no_mapping = false; init_failed = false; creation_time = current_time(); - host_val = 0; - addrs_val = 0; + host_val = nullptr; + addrs_val = nullptr; if ( ! h ) { @@ -327,7 +327,7 @@ void DNS_Mapping::Init(struct hostent* h) map_type = h->h_addrtype; num_names = 1; // for now, just use official name names = new char*[num_names]; - names[0] = h->h_name ? copy_string(h->h_name) : 0; + names[0] = h->h_name ? copy_string(h->h_name) : nullptr; for ( num_addrs = 0; h->h_addr_list[num_addrs]; ++num_addrs ) ; @@ -344,7 +344,7 @@ void DNS_Mapping::Init(struct hostent* h) IPAddr::Network); } else - addrs = 0; + addrs = nullptr; failed = false; } @@ -352,10 +352,10 @@ void DNS_Mapping::Init(struct hostent* h) void DNS_Mapping::Clear() { num_names = num_addrs = 0; - names = 0; - addrs = 0; - host_val = 0; - addrs_val = 0; + names = nullptr; + addrs = nullptr; + host_val = nullptr; + addrs_val = nullptr; no_mapping = false; map_type = 0; failed = true; @@ -363,7 +363,7 @@ void DNS_Mapping::Clear() void DNS_Mapping::Save(FILE* f) const { - fprintf(f, "%.0f %d %s %d %s %d %d %" PRIu32"\n", creation_time, req_host != 0, + fprintf(f, "%.0f %d %s %d %s %d %d %" PRIu32"\n", creation_time, req_host != nullptr, req_host ? req_host : req_addr.AsString().c_str(), failed, (names && names[0]) ? names[0] : "*", map_type, num_addrs, req_ttl); @@ -381,11 +381,11 @@ DNS_Mgr::DNS_Mgr(DNS_MgrMode arg_mode) dns_mapping_valid = dns_mapping_unverified = dns_mapping_new_name = dns_mapping_lost_name = dns_mapping_name_changed = - dns_mapping_altered = 0; + dns_mapping_altered = nullptr; - dm_rec = 0; + dm_rec = nullptr; - cache_name = dir = 0; + cache_name = dir = nullptr; asyncs_pending = 0; num_requests = 0; @@ -540,7 +540,7 @@ IntrusivePtr DNS_Mgr::LookupHost(const char* name) case DNS_FORCE: reporter->FatalError("can't find DNS entry for %s in cache", name); - return 0; + return nullptr; case DNS_DEFAULT: requests.push_back(new DNS_Mgr_Request(name, AF_INET, false)); @@ -550,7 +550,7 @@ IntrusivePtr DNS_Mgr::LookupHost(const char* name) default: reporter->InternalError("bad mode in DNS_Mgr::LookupHost"); - return 0; + return nullptr; } } @@ -585,7 +585,7 @@ IntrusivePtr DNS_Mgr::LookupAddr(const IPAddr& addr) case DNS_FORCE: reporter->FatalError("can't find DNS entry for %s in cache", addr.AsString().c_str()); - return 0; + return nullptr; case DNS_DEFAULT: requests.push_back(new DNS_Mgr_Request(addr)); @@ -594,7 +594,7 @@ IntrusivePtr DNS_Mgr::LookupAddr(const IPAddr& addr) default: reporter->InternalError("bad mode in DNS_Mgr::LookupAddr"); - return 0; + return nullptr; } } @@ -634,7 +634,7 @@ void DNS_Mgr::Resolve() DNS_Mgr_Request* dr = requests[i]; if ( dr->RequestPending() ) { - AddResult(dr, 0); + AddResult(dr, nullptr); dr->RequestDone(); } } @@ -748,7 +748,7 @@ IntrusivePtr DNS_Mgr::BuildMappingVal(DNS_Mapping* dm) void DNS_Mgr::AddResult(DNS_Mgr_Request* dr, struct nb_dns_result* r) { - struct hostent* h = (r && r->host_errno == 0) ? r->hostent : 0; + struct hostent* h = (r && r->host_errno == 0) ? r->hostent : nullptr; u_int32_t ttl = (r && r->host_errno == 0) ? r->ttl : 0; DNS_Mapping* new_dm; @@ -758,7 +758,7 @@ void DNS_Mgr::AddResult(DNS_Mgr_Request* dr, struct nb_dns_result* r) if ( dr->ReqHost() ) { new_dm = new DNS_Mapping(dr->ReqHost(), h, ttl); - prev_dm = 0; + prev_dm = nullptr; if ( dr->ReqIsTxt() ) { @@ -784,10 +784,10 @@ void DNS_Mgr::AddResult(DNS_Mgr_Request* dr, struct nb_dns_result* r) if ( it == host_mappings.end() ) { host_mappings[dr->ReqHost()].first = - new_dm->Type() == AF_INET ? new_dm : 0; + new_dm->Type() == AF_INET ? new_dm : nullptr; host_mappings[dr->ReqHost()].second = - new_dm->Type() == AF_INET ? 0 : new_dm; + new_dm->Type() == AF_INET ? nullptr : new_dm; } else { @@ -980,7 +980,7 @@ const char* DNS_Mgr::LookupAddrInCache(const IPAddr& addr) AddrMap::iterator it = addr_mappings.find(addr); if ( it == addr_mappings.end() ) - return 0; + return nullptr; DNS_Mapping* d = it->second; @@ -988,7 +988,7 @@ const char* DNS_Mgr::LookupAddrInCache(const IPAddr& addr) { addr_mappings.erase(it); delete d; - return 0; + return nullptr; } // The escapes in the following strings are to avoid having it @@ -1002,21 +1002,21 @@ IntrusivePtr DNS_Mgr::LookupNameInCache(const string& name) if ( it == host_mappings.end() ) { it = host_mappings.begin(); - return 0; + return nullptr; } DNS_Mapping* d4 = it->second.first; DNS_Mapping* d6 = it->second.second; if ( ! d4 || ! d4->names || ! d6 || ! d6->names ) - return 0; + return nullptr; if ( d4->Expired() || d6->Expired() ) { host_mappings.erase(it); delete d4; delete d6; - return 0; + return nullptr; } auto tv4 = d4->AddrsSet(); @@ -1029,7 +1029,7 @@ const char* DNS_Mgr::LookupTextInCache(const string& name) { TextMap::iterator it = text_mappings.find(name); if ( it == text_mappings.end() ) - return 0; + return nullptr; DNS_Mapping* d = it->second; @@ -1037,7 +1037,7 @@ const char* DNS_Mgr::LookupTextInCache(const string& name) { text_mappings.erase(it); delete d; - return 0; + return nullptr; } // The escapes in the following strings are to avoid having it @@ -1077,7 +1077,7 @@ void DNS_Mgr::AsyncLookupAddr(const IPAddr& host, LookupCallback* callback) return; } - AsyncRequest* req = 0; + AsyncRequest* req = nullptr; // Have we already a request waiting for this host? AsyncRequestAddrMap::iterator i = asyncs_addrs.find(host); @@ -1115,7 +1115,7 @@ void DNS_Mgr::AsyncLookupName(const string& name, LookupCallback* callback) return; } - AsyncRequest* req = 0; + AsyncRequest* req = nullptr; // Have we already a request waiting for this host? AsyncRequestNameMap::iterator i = asyncs_names.find(name); @@ -1154,7 +1154,7 @@ void DNS_Mgr::AsyncLookupNameText(const string& name, LookupCallback* callback) return; } - AsyncRequest* req = 0; + AsyncRequest* req = nullptr; // Have we already a request waiting for this host? AsyncRequestTextMap::iterator i = asyncs_texts.find(name); diff --git a/src/DbgBreakpoint.cc b/src/DbgBreakpoint.cc index 7bd18ce05f..094b46a33e 100644 --- a/src/DbgBreakpoint.cc +++ b/src/DbgBreakpoint.cc @@ -49,13 +49,13 @@ DbgBreakpoint::DbgBreakpoint() enabled = temporary = false; BPID = -1; - at_stmt = 0; + at_stmt = nullptr; at_time = -1.0; repeat_count = hit_count = 0; description[0] = 0; - source_filename = 0; + source_filename = nullptr; source_line = 0; } diff --git a/src/Debug.cc b/src/Debug.cc index 7bc6e3f4bb..3a13a4c7f7 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -55,7 +55,7 @@ DebuggerState::DebuggerState() BreakFromSignal(false); // ### Don't choose this arbitrary size! Extend Frame. - dbg_locals = new Frame(1024, /* func = */ 0, /* fn_args = */ 0); + dbg_locals = new Frame(1024, /* func = */ nullptr, /* fn_args = */ nullptr); } DebuggerState::~DebuggerState() @@ -107,7 +107,7 @@ FILE* TraceState::SetTraceFile(const char* filename) else { fprintf(stderr, "Unable to open trace file %s\n", filename); - trace_file = 0; + trace_file = nullptr; } return oldfile; @@ -137,7 +137,7 @@ int TraceState::LogTrace(const char* fmt, ...) const Stmt* stmt; Location loc; - loc.filename = 0; + loc.filename = nullptr; if ( g_frame_stack.size() > 0 && g_frame_stack.back() ) { @@ -178,7 +178,7 @@ void get_first_statement(Stmt* list, Stmt*& first, Location& loc) { if ( ! list ) { - first = 0; + first = nullptr; return; } @@ -231,7 +231,7 @@ static void parse_function_name(vector& result, return; } - Stmt* body = 0; // the particular body we care about; 0 = all + Stmt* body = nullptr; // the particular body we care about; 0 = all if ( bodies.size() == 1 ) body = bodies[0].stmts.get(); @@ -380,7 +380,7 @@ vector parse_location_string(const string& s) return result; } - StmtLocMapping* hit = 0; + StmtLocMapping* hit = nullptr; for ( const auto entry : *(iter->second) ) { plr.filename = entry->Loc().filename; @@ -399,7 +399,7 @@ vector parse_location_string(const string& s) if ( hit ) plr.stmt = hit->Statement(); else - plr.stmt = 0; + plr.stmt = nullptr; } return result; @@ -730,7 +730,7 @@ static char* get_prompt(bool reset_counter = false) string get_context_description(const Stmt* stmt, const Frame* frame) { ODesc d; - const BroFunc* func = frame ? frame->GetFunction() : 0; + const BroFunc* func = frame ? frame->GetFunction() : nullptr; if ( func ) func->DescribeDebug(&d, frame->GetFuncArgs()); @@ -758,7 +758,7 @@ string get_context_description(const Stmt* stmt, const Frame* frame) int dbg_handle_debug_input() { - static char* input_line = 0; + static char* input_line = nullptr; int status = 0; if ( g_debugger_state.BreakFromSignal() ) @@ -820,7 +820,7 @@ int dbg_handle_debug_input() if ( input_line ) { free(input_line); // this was malloc'ed - input_line = 0; + input_line = nullptr; } else exit(0); @@ -934,8 +934,8 @@ bool post_execute_stmt(Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow) // Evaluates the given expression in the context of the currently selected // frame. Returns the resulting value, or nil if none (or there was an error). -Expr* g_curr_debug_expr = 0; -const char* g_curr_debug_error = 0; +Expr* g_curr_debug_expr = nullptr; +const char* g_curr_debug_error = nullptr; bool in_debug = false; // ### fix this hardwired access to external variables etc. @@ -993,7 +993,7 @@ IntrusivePtr dbg_eval_expr(const char* expr) if ( g_curr_debug_expr ) { delete g_curr_debug_expr; - g_curr_debug_expr = 0; + g_curr_debug_expr = nullptr; } } else @@ -1003,9 +1003,9 @@ IntrusivePtr dbg_eval_expr(const char* expr) pop_scope(); delete g_curr_debug_expr; - g_curr_debug_expr = 0; + g_curr_debug_expr = nullptr; delete [] g_curr_debug_error; - g_curr_debug_error = 0; + g_curr_debug_error = nullptr; in_debug = false; return result; diff --git a/src/Debug.h b/src/Debug.h index 676c587635..bfbac98d70 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -149,7 +149,7 @@ bool post_execute_stmt(Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow); // Returns 1 if successful, 0 otherwise. // If cmdfile is non-nil, it contains the location of a file of commands // to be executed as debug commands. -int dbg_init_debugger(const char* cmdfile = 0); +int dbg_init_debugger(const char* cmdfile = nullptr); int dbg_shutdown_debugger(); // Returns 1 if successful, 0 otherwise. diff --git a/src/DebugCmds.cc b/src/DebugCmds.cc index b65d979f5e..eb284a6c69 100644 --- a/src/DebugCmds.cc +++ b/src/DebugCmds.cc @@ -125,7 +125,7 @@ void choose_global_symbols_regex(const string& regex, vector& choices, PQueue g_DebugCmdInfos; DebugCmdInfo::DebugCmdInfo(const DebugCmdInfo& info) -: cmd(info.cmd), helpstring(0) +: cmd(info.cmd), helpstring(nullptr) { num_names = info.num_names; names = info.names; @@ -153,7 +153,7 @@ const DebugCmdInfo* get_debug_cmd_info(DebugCmd cmd) if ( (int) cmd < g_DebugCmdInfos.length() ) return g_DebugCmdInfos[(int) cmd]; else - return 0; + return nullptr; } int find_all_matching_cmds(const string& prefix, const char* array_of_matches[]) @@ -165,7 +165,7 @@ int find_all_matching_cmds(const string& prefix, const char* array_of_matches[]) for ( int i = 0; i < num_debug_cmds(); ++i ) { - array_of_matches[g_DebugCmdInfos[i]->Cmd()] = 0; + array_of_matches[g_DebugCmdInfos[i]->Cmd()] = nullptr; for ( int j = 0; j < g_DebugCmdInfos[i]->NumNames(); ++j ) { @@ -177,7 +177,7 @@ int find_all_matching_cmds(const string& prefix, const char* array_of_matches[]) if ( ! prefix.compare(curr_name) ) { for ( int k = 0; k < num_debug_cmds(); ++k ) - array_of_matches[k] = 0; + array_of_matches[k] = nullptr; array_of_matches[g_DebugCmdInfos[i]->Cmd()] = curr_name; return 1; @@ -214,7 +214,7 @@ static int dbg_backtrace_internal(int start, int end) for ( int i = start; i >= end; --i ) { const Frame* f = g_frame_stack[i]; - const Stmt* stmt = f ? f->GetNextStmt() : 0; + const Stmt* stmt = f ? f->GetNextStmt() : nullptr; string context = get_context_description(stmt, f); debug_msg("#%d %s\n", diff --git a/src/DebugCmds.h b/src/DebugCmds.h index 470e4ae993..c5c84ad7fa 100644 --- a/src/DebugCmds.h +++ b/src/DebugCmds.h @@ -18,7 +18,7 @@ public: bool resume_execution, const char* const helpstring, bool repeatable); - DebugCmdInfo() : helpstring(0) {} + DebugCmdInfo() : helpstring(nullptr) {} int Cmd() const { return cmd; } int NumNames() const { return num_names; } diff --git a/src/DebugLogger.cc b/src/DebugLogger.cc index fdb57efc61..4fac89414e 100644 --- a/src/DebugLogger.cc +++ b/src/DebugLogger.cc @@ -26,7 +26,7 @@ DebugLogger::Stream DebugLogger::streams[NUM_DBGS] = { DebugLogger::DebugLogger() { verbose = false; - file = 0; + file = nullptr; } DebugLogger::~DebugLogger() diff --git a/src/Desc.cc b/src/Desc.cc index 50d95f80c8..c02347f42f 100644 --- a/src/Desc.cc +++ b/src/Desc.cc @@ -21,7 +21,7 @@ ODesc::ODesc(desc_type t, BroFile* arg_f) style = STANDARD_STYLE; f = arg_f; - if ( f == 0 ) + if ( f == nullptr ) { size = DEFAULT_SIZE; base = safe_malloc(size); @@ -31,7 +31,7 @@ ODesc::ODesc(desc_type t, BroFile* arg_f) else { offset = size = 0; - base = 0; + base = nullptr; } indent_level = 0; diff --git a/src/Desc.h b/src/Desc.h index 2a29c75a92..8896dbf52f 100644 --- a/src/Desc.h +++ b/src/Desc.h @@ -29,7 +29,7 @@ class BroType; class ODesc { public: - explicit ODesc(desc_type t=DESC_READABLE, BroFile* f=0); + explicit ODesc(desc_type t=DESC_READABLE, BroFile* f=nullptr); ~ODesc(); @@ -131,7 +131,7 @@ public: byte_vec TakeBytes() { const void* t = base; - base = 0; + base = nullptr; size = 0; // Don't clear offset, as we want to still support diff --git a/src/Dict.cc b/src/Dict.cc index 369510f7b1..1f62908c5c 100644 --- a/src/Dict.cc +++ b/src/Dict.cc @@ -81,7 +81,7 @@ TEST_CASE("dict operation") dict.Remove(key2); CHECK(dict.Length() == 0); uint32_t* lookup2 = dict.Lookup(key2); - CHECK(lookup2 == (uint32_t*)0); + CHECK(lookup2 == (uint32_t*)nullptr); delete key2; CHECK(dict.MaxLength() == 1); @@ -132,7 +132,7 @@ TEST_CASE("dict nthentry") // NthEntry returns null for unordered dicts uint32_t* lookup = unordered.NthEntry(0); - CHECK(lookup == (uint32_t*)0); + CHECK(lookup == (uint32_t*)nullptr); // Ordered dicts are based on order of insertion, nothing about the // data itself @@ -256,7 +256,7 @@ void Dictionary::DeInit() void* Dictionary::Lookup(const void* key, int key_size, hash_t hash) const { if ( ! tbl && ! tbl2 ) - return 0; + return nullptr; hash_t h; PList* chain; @@ -280,7 +280,7 @@ void* Dictionary::Lookup(const void* key, int key_size, hash_t hash) const } } - return 0; + return nullptr; } void* Dictionary::Insert(void* key, int key_size, hash_t hash, void* val, @@ -314,7 +314,7 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash, bool dont_delete) { if ( ! tbl && ! tbl2 ) - return 0; + return nullptr; hash_t h; PList* chain; @@ -334,7 +334,7 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash, } if ( ! chain ) - return 0; + return nullptr; for ( int i = 0; i < chain->length(); ++i ) { @@ -346,7 +346,7 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash, void* entry_value = DoRemove(entry, h, chain, i); if ( dont_delete ) - entry->key = 0; + entry->key = nullptr; delete entry; --*num_entries_ptr; @@ -354,7 +354,7 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash, } } - return 0; + return nullptr; } void* Dictionary::DoRemove(DictEntry* entry, hash_t h, @@ -395,7 +395,7 @@ void* Dictionary::DoRemove(DictEntry* entry, hash_t h, void* Dictionary::NthEntry(int n, const void*& key, int& key_len) const { if ( ! order || n < 0 || n >= Length() ) - return 0; + return nullptr; DictEntry* entry = (*order)[n]; key = entry->key; @@ -419,8 +419,8 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c { const_cast*>(&cookies)->remove(cookie); delete cookie; - cookie = 0; - return 0; + cookie = nullptr; + return nullptr; } // If there are any inserted entries, return them first. @@ -486,8 +486,8 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c // a better way? const_cast*>(&cookies)->remove(cookie); delete cookie; - cookie = 0; - return 0; + cookie = nullptr; + return nullptr; } entry = (*ttbl[b])[0]; @@ -604,7 +604,7 @@ void* Dictionary::Insert(DictEntry* new_entry, bool copy_key) c->inserted.push_back(new_entry); } - return 0; + return nullptr; } int Dictionary::NextPrime(int n) const @@ -665,7 +665,7 @@ void Dictionary::MoveChains() if ( ! chain ) continue; - tbl[tbl_next_ind - 1] = 0; + tbl[tbl_next_ind - 1] = nullptr; for ( int j = 0; j < chain->length(); ++j ) { diff --git a/src/Dict.h b/src/Dict.h index b5edeba76b..a611c1b3f1 100644 --- a/src/Dict.h +++ b/src/Dict.h @@ -70,7 +70,7 @@ public: } // True if the dictionary is ordered, false otherwise. - bool IsOrdered() const { return order != 0; } + bool IsOrdered() const { return order != nullptr; } // If the dictionary is ordered then returns the n'th entry's value; // the second method also returns the key. The first entry inserted diff --git a/src/EquivClass.cc b/src/EquivClass.cc index c067137227..39bc2699c2 100644 --- a/src/EquivClass.cc +++ b/src/EquivClass.cc @@ -12,7 +12,7 @@ EquivClass::EquivClass(int arg_size) bck = new int[size]; equiv_class = new int[size]; rep = new int[size]; - ccl_flags = 0; + ccl_flags = nullptr; num_ecs = 0; ec_nil = no_class = no_rep = size + 1; diff --git a/src/Event.cc b/src/Event.cc index c33fba5929..11e34b0117 100644 --- a/src/Event.cc +++ b/src/Event.cc @@ -74,10 +74,10 @@ void Event::Dispatch(bool no_remote) EventMgr::EventMgr() { - head = tail = 0; + head = tail = nullptr; current_src = SOURCE_LOCAL; current_aid = 0; - src_val = 0; + src_val = nullptr; draining = false; } @@ -176,8 +176,8 @@ void EventMgr::Drain() for ( int round = 0; head && round < 2; round++ ) { Event* current = head; - head = 0; - tail = 0; + head = nullptr; + tail = nullptr; while ( current ) { diff --git a/src/Event.h b/src/Event.h index 6bf43a0aa4..44ede22e66 100644 --- a/src/Event.h +++ b/src/Event.h @@ -64,7 +64,7 @@ public: [[deprecated("Remove in v4.1. Use Enqueue() instead.")]] void QueueEventFast(const EventHandlerPtr &h, val_list vl, SourceID src = SOURCE_LOCAL, analyzer::ID aid = 0, - TimerMgr* mgr = 0, BroObj* obj = 0); + TimerMgr* mgr = nullptr, BroObj* obj = nullptr); // Queues an event if there's an event handler (or remote consumer). This // function always takes ownership of decrementing the reference count of @@ -75,7 +75,7 @@ public: [[deprecated("Remove in v4.1. Use Enqueue() instead.")]] void QueueEvent(const EventHandlerPtr &h, val_list vl, SourceID src = SOURCE_LOCAL, analyzer::ID aid = 0, - TimerMgr* mgr = 0, BroObj* obj = 0); + TimerMgr* mgr = nullptr, BroObj* obj = nullptr); // Same as QueueEvent, except taking the event's argument list via a // pointer instead of by value. This function takes ownership of the @@ -84,7 +84,7 @@ public: [[deprecated("Remove in v4.1. Use Enqueue() instead.")]] void QueueEvent(const EventHandlerPtr &h, val_list* vl, SourceID src = SOURCE_LOCAL, analyzer::ID aid = 0, - TimerMgr* mgr = 0, BroObj* obj = 0); + TimerMgr* mgr = nullptr, BroObj* obj = nullptr); /** * Adds an event to the queue. If no handler is found for the event @@ -117,7 +117,7 @@ public: void Drain(); bool IsDraining() const { return draining; } - bool HasEvents() const { return head != 0; } + bool HasEvents() const { return head != nullptr; } // Returns the source ID of last raised event. SourceID CurrentSource() const { return current_src; } diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 8f35d47ed5..c1fad45a91 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -13,8 +13,8 @@ EventHandler::EventHandler(const char* arg_name) { name = copy_string(arg_name); used = false; - local = 0; - type = 0; + local = nullptr; + type = nullptr; error_handler = false; enabled = true; generate_always = false; @@ -42,10 +42,10 @@ FuncType* EventHandler::FType(bool check_export) check_export); if ( ! id ) - return 0; + return nullptr; if ( id->Type()->Tag() != TYPE_FUNC ) - return 0; + return nullptr; type = id->Type()->AsFuncType(); return type; diff --git a/src/EventHandler.h b/src/EventHandler.h index effafb134e..59773560f6 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -69,7 +69,7 @@ private: // Encapsulates a ptr to an event handler to overload the boolean operator. class EventHandlerPtr { public: - EventHandlerPtr(EventHandler* p = 0) { handler = p; } + EventHandlerPtr(EventHandler* p = nullptr) { handler = p; } EventHandlerPtr(const EventHandlerPtr& h) { handler = h.handler; } const EventHandlerPtr& operator=(EventHandler* p) diff --git a/src/Expr.cc b/src/Expr.cc index 0c99f01012..cb34859ea6 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -54,7 +54,7 @@ const char* expr_name(BroExprTag t) return expr_names[int(t)]; } -Expr::Expr(BroExprTag arg_tag) : tag(arg_tag), type(0), paren(false) +Expr::Expr(BroExprTag arg_tag) : tag(arg_tag), type(nullptr), paren(false) { SetLocationInfo(&start_location, &end_location); } @@ -1623,7 +1623,7 @@ IntrusivePtr BoolExpr::Eval(Frame* f) const result->Assign(i, val_mgr->GetBool(local_result)); } else - result->Assign(i, 0); + result->Assign(i, nullptr); } return result; @@ -1952,7 +1952,7 @@ IntrusivePtr CondExpr::Eval(Frame* f) const result->Assign(i, v ? v->Ref() : nullptr); } else - result->Assign(i, 0); + result->Assign(i, nullptr); } return result; @@ -2019,7 +2019,7 @@ AssignExpr::AssignExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, std::move(arg_op1) : arg_op1->MakeLvalue(), std::move(arg_op2)) { - val = 0; + val = nullptr; is_init = arg_is_init; if ( IsError() ) @@ -2079,7 +2079,7 @@ bool AssignExpr::TypeCheck(attr_list* attrs) if ( bt1 == TYPE_TABLE && op2->Tag() == EXPR_LIST ) { - attr_list* attr_copy = 0; + attr_list* attr_copy = nullptr; if ( attrs ) { @@ -2178,7 +2178,7 @@ bool AssignExpr::TypeCheck(attr_list* attrs) return false; } - attr_list* attr_copy = 0; + attr_list* attr_copy = nullptr; if ( sce->Attrs() ) { @@ -2293,7 +2293,7 @@ void AssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const if ( IsError() ) return; - TypeDecl td(0, 0); + TypeDecl td(nullptr, nullptr); if ( IsRecordElement(&td) ) { @@ -2348,7 +2348,7 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) if ( IsError() ) return nullptr; - TypeDecl td(0, 0); + TypeDecl td(nullptr, nullptr); if ( IsRecordElement(&td) ) { @@ -2690,7 +2690,7 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const const ListVal* lv = v2->AsListVal(); const BroString* s = v1->AsString(); int len = s->Len(); - BroString* substring = 0; + BroString* substring = nullptr; if ( lv->Length() == 1 ) { @@ -2709,7 +2709,7 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const bro_int_t substring_len = last - first; if ( substring_len < 0 ) - substring = 0; + substring = nullptr; else substring = s->GetSubstring(first, substring_len); } @@ -2851,7 +2851,7 @@ TraversalCode IndexExpr::Traverse(TraversalCallback* cb) const FieldExpr::FieldExpr(IntrusivePtr arg_op, const char* arg_field_name) : UnaryExpr(EXPR_FIELD, std::move(arg_op)), - field_name(copy_string(arg_field_name)), td(0), field(0) + field_name(copy_string(arg_field_name)), td(nullptr), field(0) { if ( IsError() ) return; @@ -2905,7 +2905,7 @@ void FieldExpr::Assign(Frame* f, IntrusivePtr v) void FieldExpr::Delete(Frame* f) { - Assign(f, 0); + Assign(f, nullptr); } IntrusivePtr FieldExpr::Fold(Val* v) const @@ -2914,7 +2914,7 @@ IntrusivePtr FieldExpr::Fold(Val* v) const return {NewRef{}, result}; // Check for &default. - const Attr* def_attr = td ? td->FindAttr(ATTR_DEFAULT) : 0; + const Attr* def_attr = td ? td->FindAttr(ATTR_DEFAULT) : nullptr; if ( def_attr ) return def_attr->AttrExpr()->Eval(nullptr); @@ -3101,7 +3101,7 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_li } } - attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : 0; + attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr; type_list* indices = type->AsTableType()->Indices()->Types(); const expr_list& cle = op->AsListExpr()->Exprs(); @@ -3173,7 +3173,7 @@ IntrusivePtr TableConstructorExpr::InitVal(const BroType* t, IntrusivePtrAsListExpr()->Exprs(); for ( const auto& expr : exprs ) - expr->EvalIntoAggregate(t, tval.get(), 0); + expr->EvalIntoAggregate(t, tval.get(), nullptr); return tval; } @@ -3219,7 +3219,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, else if ( type->Tag() != TYPE_TABLE || ! type->AsTableType()->IsSet() ) SetError("values in set(...) constructor do not specify a set"); - attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : 0; + attrs = arg_attrs ? new Attributes(arg_attrs, type, false, false) : nullptr; type_list* indices = type->AsTableType()->Indices()->Types(); expr_list& cle = op->AsListExpr()->Exprs(); @@ -3265,7 +3265,7 @@ IntrusivePtr SetConstructorExpr::Eval(Frame* f) const for ( const auto& expr : exprs ) { auto element = expr->Eval(f); - aggr->Assign(element.get(), 0); + aggr->Assign(element.get(), nullptr); } return aggr; @@ -3287,7 +3287,7 @@ IntrusivePtr SetConstructorExpr::InitVal(const BroType* t, IntrusivePtrEval(nullptr), index_type, true); - if ( ! element || ! tval->Assign(element.get(), 0) ) + if ( ! element || ! tval->Assign(element.get(), nullptr) ) { Error(fmt("initialization type mismatch in set"), e); return nullptr; @@ -3521,7 +3521,7 @@ IntrusivePtr ArithCoerceExpr::Fold(Val* v) const if ( Val* elt = vv->Lookup(i) ) result->Assign(i, FoldSingleVal(elt, t)); else - result->Assign(i, 0); + result->Assign(i, nullptr); } return result; @@ -4191,7 +4191,7 @@ IntrusivePtr CallExpr::Eval(Frame* f) const if ( func_val && v ) { const ::Func* funcv = func_val->AsFunc(); - const CallExpr* current_call = f ? f->GetCall() : 0; + const CallExpr* current_call = f ? f->GetCall() : nullptr; if ( f ) f->SetCall(this); @@ -4491,12 +4491,12 @@ IntrusivePtr ListExpr::InitType() const return nullptr; } - if ( exprs[0]->IsRecordElement(0) ) + if ( exprs[0]->IsRecordElement(nullptr) ) { type_decl_list* types = new type_decl_list(exprs.length()); for ( const auto& expr : exprs ) { - TypeDecl* td = new TypeDecl(0, 0); + TypeDecl* td = new TypeDecl(nullptr, nullptr); if ( ! expr->IsRecordElement(td) ) { expr->Error("record element expected"); @@ -5063,7 +5063,7 @@ bool check_and_promote_args(ListExpr* const args, RecordType* types) for ( int i = ntypes - 1; i >= el.length(); --i ) { TypeDecl* td = types->FieldDecl(i); - Attr* def_attr = td->attrs ? td->attrs->FindAttr(ATTR_DEFAULT) : 0; + Attr* def_attr = td->attrs ? td->attrs->FindAttr(ATTR_DEFAULT) : nullptr; if ( ! def_attr ) { diff --git a/src/Expr.h b/src/Expr.h index 1ed01a57a9..4727b5c670 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -523,7 +523,7 @@ public: bool IsPure() const override; protected: - bool TypeCheck(attr_list* attrs = 0); + bool TypeCheck(attr_list* attrs = nullptr); bool TypeCheckArithmetics(TypeTag bt1, TypeTag bt2); bool is_init; diff --git a/src/File.cc b/src/File.cc index ade6918715..7581b9fb3b 100644 --- a/src/File.cc +++ b/src/File.cc @@ -56,9 +56,9 @@ BroFile::BroFile(FILE* arg_f) { Init(); f = arg_f; - name = access = 0; + name = access = nullptr; t = base_type(TYPE_STRING); - is_open = (f != 0); + is_open = (f != nullptr); } BroFile::BroFile(FILE* arg_f, const char* arg_name, const char* arg_access) @@ -68,13 +68,13 @@ BroFile::BroFile(FILE* arg_f, const char* arg_name, const char* arg_access) name = copy_string(arg_name); access = copy_string(arg_access); t = base_type(TYPE_STRING); - is_open = (f != 0); + is_open = (f != nullptr); } BroFile::BroFile(const char* arg_name, const char* arg_access) { Init(); - f = 0; + f = nullptr; name = copy_string(arg_name); access = copy_string(arg_access); t = base_type(TYPE_STRING); @@ -110,7 +110,7 @@ const char* BroFile::Name() const if ( f == stderr ) return "/dev/stderr"; - return 0; + return nullptr; } bool BroFile::Open(FILE* file, const char* mode) @@ -168,7 +168,7 @@ void BroFile::Init() { open_time = 0; is_open = false; - attrs = 0; + attrs = nullptr; buffered = true; raw_output = false; @@ -185,7 +185,7 @@ FILE* BroFile::File() FILE* BroFile::Seek(long new_position) { if ( ! File() ) - return 0; + return nullptr; if ( fseek(f, new_position, SEEK_SET) < 0 ) reporter->Error("seek failed"); @@ -271,11 +271,11 @@ void BroFile::SetAttrs(Attributes* arg_attrs) RecordVal* BroFile::Rotate() { if ( ! is_open ) - return 0; + return nullptr; // Do not rotate stdin/stdout/stderr. if ( f == stdin || f == stdout || f == stderr ) - return 0; + return nullptr; RecordVal* info = new RecordVal(rotate_info); FILE* newf = rotate_file(name, info); @@ -283,7 +283,7 @@ RecordVal* BroFile::Rotate() if ( ! newf ) { Unref(info); - return 0; + return nullptr; } info->Assign(2, make_intrusive(open_time, TYPE_TIME)); @@ -291,7 +291,7 @@ RecordVal* BroFile::Rotate() Unlink(); fclose(f); - f = 0; + f = nullptr; Open(newf); return info; diff --git a/src/File.h b/src/File.h index 2d10237a76..c811a958be 100644 --- a/src/File.h +++ b/src/File.h @@ -80,7 +80,7 @@ protected: * If file is not given and mode is, the filename will be opened with that * access mode. */ - bool Open(FILE* f = nullptr, const char* mode = 0); + bool Open(FILE* f = nullptr, const char* mode = nullptr); void Unlink(); diff --git a/src/Frag.cc b/src/Frag.cc index c571a039d5..c155a91f51 100644 --- a/src/Frag.cc +++ b/src/Frag.cc @@ -49,7 +49,7 @@ FragReassembler::FragReassembler(NetSessions* arg_s, memcpy(proto_hdr, ip->IP6_Hdr(), proto_hdr_len); } - reassembled_pkt = 0; + reassembled_pkt = nullptr; frag_size = 0; // flag meaning "not known" next_proto = ip->NextProto(); @@ -59,7 +59,7 @@ FragReassembler::FragReassembler(NetSessions* arg_s, timer_mgr->Add(expire_timer); } else - expire_timer = 0; + expire_timer = nullptr; AddFragment(t, ip, pkt); } @@ -285,7 +285,7 @@ void FragReassembler::BlockInserted(DataBlockMap::const_iterator /* it */) } delete reassembled_pkt; - reassembled_pkt = 0; + reassembled_pkt = nullptr; unsigned int version = ((const struct ip*)pkt_start)->ip_v; @@ -318,7 +318,7 @@ void FragReassembler::Expire(double t) { block_list.Clear(); expire_timer->ClearReassembler(); - expire_timer = 0; // timer manager will delete it + expire_timer = nullptr; // timer manager will delete it sessions->Remove(this); } @@ -329,6 +329,6 @@ void FragReassembler::DeleteTimer() { expire_timer->ClearReassembler(); timer_mgr->Cancel(expire_timer); - expire_timer = 0; // timer manager will delete it + expire_timer = nullptr; // timer manager will delete it } } diff --git a/src/Frag.h b/src/Frag.h index 31d5ec5bd0..ca81c54887 100644 --- a/src/Frag.h +++ b/src/Frag.h @@ -32,7 +32,7 @@ public: void Expire(double t); void DeleteTimer(); - void ClearTimer() { expire_timer = 0; } + void ClearTimer() { expire_timer = nullptr; } const IP_Hdr* ReassembledPkt() { return reassembled_pkt; } const FragReassemblerKey& Key() const { return key; } @@ -63,7 +63,7 @@ public: void Dispatch(double t, bool is_expire) override; // Break the association between this timer and its creator. - void ClearReassembler() { f = 0; } + void ClearReassembler() { f = nullptr; } protected: FragReassembler* f; diff --git a/src/Frame.cc b/src/Frame.cc index 1c093398dc..09e95dad33 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -136,7 +136,7 @@ void Frame::Reset(int startIdx) for ( int i = startIdx; i < size; ++i ) { UnrefElement(i); - frame[i] = 0; + frame[i] = nullptr; } } @@ -159,7 +159,7 @@ void Frame::Describe(ODesc* d) const for ( int i = 0; i < size; ++i ) { - d->Add(frame[i] != 0); + d->Add(frame[i] != nullptr); d->SP(); } } diff --git a/src/Frame.h b/src/Frame.h index 0961290ab1..2a5acab11e 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -217,7 +217,7 @@ public: trigger::Trigger* GetTrigger() const { return trigger.get(); } void SetCall(const CallExpr* arg_call) { call = arg_call; } - void ClearCall() { call = 0; } + void ClearCall() { call = nullptr; } const CallExpr* GetCall() const { return call; } void SetDelayed() { delayed = true; } diff --git a/src/Func.h b/src/Func.h index c414e3ac85..3f75226c1a 100644 --- a/src/Func.h +++ b/src/Func.h @@ -97,7 +97,7 @@ public: uint32_t GetUniqueFuncID() const { return unique_id; } static Func* GetFuncPtrByID(uint32_t id) - { return id >= unique_ids.size() ? 0 : unique_ids[id]; } + { return id >= unique_ids.size() ? nullptr : unique_ids[id]; } protected: Func(); @@ -205,7 +205,7 @@ public: void Describe(ODesc* d) const override; protected: - BuiltinFunc() { func = 0; is_pure = 0; } + BuiltinFunc() { func = nullptr; is_pure = 0; } built_in_func func; bool is_pure; diff --git a/src/ID.cc b/src/ID.cc index e0caea3b2d..3494d8a175 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -25,7 +25,7 @@ ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export) scope = arg_scope; is_export = arg_is_export; is_option = false; - val = 0; + val = nullptr; is_const = false; is_enum_const = false; is_type = false; @@ -60,7 +60,7 @@ void ID::ClearVal() if ( ! weak_ref ) Unref(val); - val = 0; + val = nullptr; } void ID::SetVal(IntrusivePtr v, bool arg_weak_ref) @@ -147,12 +147,12 @@ void ID::SetVal(IntrusivePtr ev, init_class c) bool ID::IsRedefinable() const { - return FindAttr(ATTR_REDEF) != 0; + return FindAttr(ATTR_REDEF) != nullptr; } void ID::SetAttrs(IntrusivePtr a) { - attrs = 0; + attrs = nullptr; AddAttrs(std::move(a)); } @@ -197,12 +197,12 @@ void ID::UpdateValAttrs() Attr* ID::FindAttr(attr_tag t) const { - return attrs ? attrs->FindAttr(t) : 0; + return attrs ? attrs->FindAttr(t) : nullptr; } bool ID::IsDeprecated() const { - return FindAttr(ATTR_DEPRECATED) != 0; + return FindAttr(ATTR_DEPRECATED) != nullptr; } void ID::MakeDeprecated(IntrusivePtr deprecation) diff --git a/src/ID.h b/src/ID.h index ee96ea7845..b7cca8237d 100644 --- a/src/ID.h +++ b/src/ID.h @@ -41,8 +41,8 @@ public: const BroType* Type() const { return type.get(); } void MakeType() { is_type = true; } - BroType* AsType() { return is_type ? Type() : 0; } - const BroType* AsType() const { return is_type ? Type() : 0; } + BroType* AsType() { return is_type ? Type() : nullptr; } + const BroType* AsType() const { return is_type ? Type() : nullptr; } // If weak_ref is false, the Val is assumed to be already ref'ed // and will be deref'ed when the ID is deleted. @@ -57,7 +57,7 @@ public: void SetVal(IntrusivePtr v, init_class c); void SetVal(IntrusivePtr ev, init_class c); - bool HasVal() const { return val != 0; } + bool HasVal() const { return val != nullptr; } Val* ID_Val() { return val; } const Val* ID_Val() const { return val; } void ClearVal(); @@ -90,7 +90,7 @@ public: std::string GetDeprecationWarning() const; - void Error(const char* msg, const BroObj* o2 = 0); + void Error(const char* msg, const BroObj* o2 = nullptr); void Describe(ODesc* d) const override; // Adds type and value to description. diff --git a/src/IP.cc b/src/IP.cc index 65c34c8e40..019bec0790 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -13,26 +13,26 @@ #include "BroString.h" #include "Reporter.h" -static RecordType* ip4_hdr_type = 0; -static RecordType* ip6_hdr_type = 0; -static RecordType* ip6_ext_hdr_type = 0; -static RecordType* ip6_option_type = 0; -static RecordType* ip6_hopopts_type = 0; -static RecordType* ip6_dstopts_type = 0; -static RecordType* ip6_routing_type = 0; -static RecordType* ip6_fragment_type = 0; -static RecordType* ip6_ah_type = 0; -static RecordType* ip6_esp_type = 0; -static RecordType* ip6_mob_type = 0; -static RecordType* ip6_mob_msg_type = 0; -static RecordType* ip6_mob_brr_type = 0; -static RecordType* ip6_mob_hoti_type = 0; -static RecordType* ip6_mob_coti_type = 0; -static RecordType* ip6_mob_hot_type = 0; -static RecordType* ip6_mob_cot_type = 0; -static RecordType* ip6_mob_bu_type = 0; -static RecordType* ip6_mob_back_type = 0; -static RecordType* ip6_mob_be_type = 0; +static RecordType* ip4_hdr_type = nullptr; +static RecordType* ip6_hdr_type = nullptr; +static RecordType* ip6_ext_hdr_type = nullptr; +static RecordType* ip6_option_type = nullptr; +static RecordType* ip6_hopopts_type = nullptr; +static RecordType* ip6_dstopts_type = nullptr; +static RecordType* ip6_routing_type = nullptr; +static RecordType* ip6_fragment_type = nullptr; +static RecordType* ip6_ah_type = nullptr; +static RecordType* ip6_esp_type = nullptr; +static RecordType* ip6_mob_type = nullptr; +static RecordType* ip6_mob_msg_type = nullptr; +static RecordType* ip6_mob_brr_type = nullptr; +static RecordType* ip6_mob_hoti_type = nullptr; +static RecordType* ip6_mob_coti_type = nullptr; +static RecordType* ip6_mob_hot_type = nullptr; +static RecordType* ip6_mob_cot_type = nullptr; +static RecordType* ip6_mob_bu_type = nullptr; +static RecordType* ip6_mob_back_type = nullptr; +static RecordType* ip6_mob_be_type = nullptr; static inline RecordType* hdrType(RecordType*& type, const char* name) { @@ -79,7 +79,7 @@ static VectorVal* BuildOptionsVal(const u_char* data, int len) RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const { - RecordVal* rv = 0; + RecordVal* rv = nullptr; switch ( type ) { case IPPROTO_IPV6: @@ -330,7 +330,7 @@ IPAddr IP_Hdr::DstAddr() const RecordVal* IP_Hdr::BuildIPHdrVal() const { - RecordVal* rval = 0; + RecordVal* rval = nullptr; if ( ip4 ) { @@ -354,7 +354,7 @@ RecordVal* IP_Hdr::BuildIPHdrVal() const RecordVal* IP_Hdr::BuildPktHdrVal() const { - static RecordType* pkt_hdr_type = 0; + static RecordType* pkt_hdr_type = nullptr; if ( ! pkt_hdr_type ) pkt_hdr_type = internal_type("pkt_hdr")->AsRecordType(); @@ -365,9 +365,9 @@ RecordVal* IP_Hdr::BuildPktHdrVal() const RecordVal* IP_Hdr::BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const { - static RecordType* tcp_hdr_type = 0; - static RecordType* udp_hdr_type = 0; - static RecordType* icmp_hdr_type = 0; + static RecordType* tcp_hdr_type = nullptr; + static RecordType* udp_hdr_type = nullptr; + static RecordType* icmp_hdr_type = nullptr; if ( ! tcp_hdr_type ) { diff --git a/src/IP.h b/src/IP.h index 287bcf8fad..5eaac66a2b 100644 --- a/src/IP.h +++ b/src/IP.h @@ -136,7 +136,7 @@ public: /** * Returns the script-layer record representation of the header. */ - RecordVal* BuildRecordVal(VectorVal* chain = 0) const; + RecordVal* BuildRecordVal(VectorVal* chain = nullptr) const; protected: uint8_t type; @@ -184,7 +184,7 @@ public: */ const struct ip6_frag* GetFragHdr() const { return IsFragment() ? - (const struct ip6_frag*)chain[chain.size()-1]->Data(): 0; } + (const struct ip6_frag*)chain[chain.size()-1]->Data(): nullptr; } /** * If the header chain is a fragment, returns the offset in number of bytes diff --git a/src/NFA.cc b/src/NFA.cc index f22b4e0b21..94de8260d7 100644 --- a/src/NFA.cc +++ b/src/NFA.cc @@ -14,11 +14,11 @@ static int nfa_state_id = 0; NFA_State::NFA_State(int arg_sym, EquivClass* ec) { sym = arg_sym; - ccl = 0; + ccl = nullptr; accept = NO_ACCEPT; first_trans_is_back_ref = false; - mark = 0; - epsclosure = 0; + mark = nullptr; + epsclosure = nullptr; id = ++nfa_state_id; // Fix up equivalence classes based on this transition. Note that any @@ -39,9 +39,9 @@ NFA_State::NFA_State(CCL* arg_ccl) ccl = arg_ccl; accept = NO_ACCEPT; first_trans_is_back_ref = false; - mark = 0; + mark = nullptr; id = ++nfa_state_id; - epsclosure = 0; + epsclosure = nullptr; } NFA_State::~NFA_State() @@ -67,7 +67,7 @@ NFA_State* NFA_State::DeepCopy() return mark; } - NFA_State* copy = ccl ? new NFA_State(ccl) : new NFA_State(sym, 0); + NFA_State* copy = ccl ? new NFA_State(ccl) : new NFA_State(sym, nullptr); SetMark(copy); for ( int i = 0; i < xtions.length(); ++i ) @@ -80,7 +80,7 @@ void NFA_State::ClearMarks() { if ( mark ) { - SetMark(0); + SetMark(nullptr); for ( int i = 0; i < xtions.length(); ++i ) xtions[i]->ClearMarks(); } @@ -125,7 +125,7 @@ NFA_state_list* NFA_State::EpsilonClosure() // Clear out markers. for ( i = 0; i < states.length(); ++i ) - states[i]->SetMark(0); + states[i]->SetMark(nullptr); // Make it fit. epsclosure->resize(0); @@ -262,7 +262,7 @@ void NFA_Machine::MakePositiveClosure() void NFA_Machine::MakeRepl(int lower, int upper) { - NFA_Machine* dup = 0; + NFA_Machine* dup = nullptr; if ( upper > lower || upper == NO_UPPER_BOUND ) dup = DuplicateMachine(); diff --git a/src/NFA.h b/src/NFA.h index 6b6827acc2..77e0102fba 100644 --- a/src/NFA.h +++ b/src/NFA.h @@ -78,12 +78,12 @@ protected: class EpsilonState : public NFA_State { public: - EpsilonState() : NFA_State(SYM_EPSILON, 0) { } + EpsilonState() : NFA_State(SYM_EPSILON, nullptr) { } }; class NFA_Machine : public BroObj { public: - explicit NFA_Machine(NFA_State* first, NFA_State* final = 0); + explicit NFA_Machine(NFA_State* first, NFA_State* final = nullptr); ~NFA_Machine() override; NFA_State* FirstState() const { return first_state; } diff --git a/src/Net.cc b/src/Net.cc index 6aa3177639..21542aad04 100644 --- a/src/Net.cc +++ b/src/Net.cc @@ -115,7 +115,7 @@ RETSIGTYPE watchdog(int /* signo */) if ( ! pkt_dumper || pkt_dumper->IsError() ) { reporter->Error("watchdog: can't open watchdog-pkt.pcap for writing"); - pkt_dumper = 0; + pkt_dumper = nullptr; } } diff --git a/src/Net.h b/src/Net.h index e7b7f3bd7f..dc121ec9e0 100644 --- a/src/Net.h +++ b/src/Net.h @@ -30,7 +30,7 @@ extern void net_delete(); // Reclaim all memory, etc. extern void net_update_time(double new_network_time); extern void net_packet_dispatch(double t, const Packet* pkt, iosource::PktSrc* src_ps); -extern void expire_timers(iosource::PktSrc* src_ps = 0); +extern void expire_timers(iosource::PktSrc* src_ps = nullptr); extern void zeek_terminate_loop(const char* reason); // Functions to temporarily suspend processing of live input (network packets diff --git a/src/Obj.cc b/src/Obj.cc index 43cee1e7d6..89edc8edff 100644 --- a/src/Obj.cc +++ b/src/Obj.cc @@ -165,7 +165,7 @@ void BroObj::DoMsg(ODesc* d, const char s1[], const BroObj* obj2, d->Add(s1); PinPoint(d, obj2, pinpoint_only); - const Location* loc2 = 0; + const Location* loc2 = nullptr; if ( obj2 && obj2->GetLocationInfo() != &no_location && *obj2->GetLocationInfo() != *GetLocationInfo() ) loc2 = obj2->GetLocationInfo(); diff --git a/src/Obj.h b/src/Obj.h index ec09dd8571..cab0ab92d5 100644 --- a/src/Obj.h +++ b/src/Obj.h @@ -66,7 +66,7 @@ public: // we check for whether start_location has a line number // of 0, which should only happen if it's been assigned // to no_location (or hasn't been initialized at all). - location = 0; + location = nullptr; if ( start_location.first_line != 0 ) SetLocationInfo(&start_location, &end_location); } @@ -80,14 +80,14 @@ public: // Report user warnings/errors. If obj2 is given, then it's // included in the message, though if pinpoint_only is non-zero, // then obj2 is only used to pinpoint the location. - void Warn(const char* msg, const BroObj* obj2 = 0, - bool pinpoint_only = false, const Location* expr_location = 0) const; - void Error(const char* msg, const BroObj* obj2 = 0, - bool pinpoint_only = false, const Location* expr_location = 0) const; + void Warn(const char* msg, const BroObj* obj2 = nullptr, + bool pinpoint_only = false, const Location* expr_location = nullptr) const; + void Error(const char* msg, const BroObj* obj2 = nullptr, + bool pinpoint_only = false, const Location* expr_location = nullptr) const; // Report internal errors. - void BadTag(const char* msg, const char* t1 = 0, - const char* t2 = 0) const; + void BadTag(const char* msg, const char* t1 = nullptr, + const char* t2 = nullptr) const; #define CHECK_TAG(t1, t2, text, tag_to_text_func) \ { \ if ( t1 != t2 ) \ @@ -134,9 +134,9 @@ protected: private: friend class SuppressErrors; - void DoMsg(ODesc* d, const char s1[], const BroObj* obj2 = 0, - bool pinpoint_only = false, const Location* expr_location = 0) const; - void PinPoint(ODesc* d, const BroObj* obj2 = 0, + void DoMsg(ODesc* d, const char s1[], const BroObj* obj2 = nullptr, + bool pinpoint_only = false, const Location* expr_location = nullptr) const; + void PinPoint(ODesc* d, const BroObj* obj2 = nullptr, bool pinpoint_only = false) const; friend inline void Ref(BroObj* o); diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index b8d7669d54..607376ed60 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -699,24 +699,24 @@ bool EntropyVal::DoUnserialize(const broker::data& data) BloomFilterVal::BloomFilterVal() : OpaqueVal(bloomfilter_type) { - type = 0; - hash = 0; - bloom_filter = 0; + type = nullptr; + hash = nullptr; + bloom_filter = nullptr; } BloomFilterVal::BloomFilterVal(OpaqueType* t) : OpaqueVal(t) { - type = 0; - hash = 0; - bloom_filter = 0; + type = nullptr; + hash = nullptr; + bloom_filter = nullptr; } BloomFilterVal::BloomFilterVal(probabilistic::BloomFilter* bf) : OpaqueVal(bloomfilter_type) { - type = 0; - hash = 0; + type = nullptr; + hash = nullptr; bloom_filter = bf; } @@ -790,13 +790,13 @@ IntrusivePtr BloomFilterVal::Merge(const BloomFilterVal* x, ! same_type(x->Type(), y->Type()) ) { reporter->Error("cannot merge Bloom filters with different types"); - return 0; + return nullptr; } if ( typeid(*x->bloom_filter) != typeid(*y->bloom_filter) ) { reporter->Error("cannot merge different Bloom filter types"); - return 0; + return nullptr; } probabilistic::BloomFilter* copy = x->bloom_filter->Clone(); @@ -805,7 +805,7 @@ IntrusivePtr BloomFilterVal::Merge(const BloomFilterVal* x, { delete copy; reporter->Error("failed to merge Bloom filter"); - return 0; + return nullptr; } auto merged = make_intrusive(copy); @@ -813,7 +813,7 @@ IntrusivePtr BloomFilterVal::Merge(const BloomFilterVal* x, if ( x->Type() && ! merged->Typify(x->Type()) ) { reporter->Error("failed to set type on merged Bloom filter"); - return 0; + return nullptr; } return merged; @@ -876,17 +876,17 @@ bool BloomFilterVal::DoUnserialize(const broker::data& data) CardinalityVal::CardinalityVal() : OpaqueVal(cardinality_type) { - c = 0; - type = 0; - hash = 0; + c = nullptr; + type = nullptr; + hash = nullptr; } CardinalityVal::CardinalityVal(probabilistic::CardinalityCounter* arg_c) : OpaqueVal(cardinality_type) { c = arg_c; - type = 0; - hash = 0; + type = nullptr; + hash = nullptr; } CardinalityVal::~CardinalityVal() diff --git a/src/Options.cc b/src/Options.cc index c4f864189a..a68f76595c 100644 --- a/src/Options.cc +++ b/src/Options.cc @@ -186,49 +186,49 @@ zeek::Options zeek::parse_cmdline(int argc, char** argv) } constexpr struct option long_opts[] = { - {"parse-only", no_argument, 0, 'a'}, - {"bare-mode", no_argument, 0, 'b'}, - {"debug-script", no_argument, 0, 'd'}, - {"exec", required_argument, 0, 'e'}, - {"filter", required_argument, 0, 'f'}, - {"help", no_argument, 0, 'h'}, - {"iface", required_argument, 0, 'i'}, - {"zeekygen", required_argument, 0, 'X'}, - {"prefix", required_argument, 0, 'p'}, - {"readfile", required_argument, 0, 'r'}, - {"rulefile", required_argument, 0, 's'}, - {"tracefile", required_argument, 0, 't'}, - {"writefile", required_argument, 0, 'w'}, - {"version", no_argument, 0, 'v'}, - {"no-checksums", no_argument, 0, 'C'}, - {"force-dns", no_argument, 0, 'F'}, - {"load-seeds", required_argument, 0, 'G'}, - {"save-seeds", required_argument, 0, 'H'}, - {"print-plugins", no_argument, 0, 'N'}, - {"prime-dns", no_argument, 0, 'P'}, - {"time", no_argument, 0, 'Q'}, - {"debug-rules", no_argument, 0, 'S'}, - {"re-level", required_argument, 0, 'T'}, - {"watchdog", no_argument, 0, 'W'}, - {"print-id", required_argument, 0, 'I'}, - {"status-file", required_argument, 0, 'U'}, + {"parse-only", no_argument, nullptr, 'a'}, + {"bare-mode", no_argument, nullptr, 'b'}, + {"debug-script", no_argument, nullptr, 'd'}, + {"exec", required_argument, nullptr, 'e'}, + {"filter", required_argument, nullptr, 'f'}, + {"help", no_argument, nullptr, 'h'}, + {"iface", required_argument, nullptr, 'i'}, + {"zeekygen", required_argument, nullptr, 'X'}, + {"prefix", required_argument, nullptr, 'p'}, + {"readfile", required_argument, nullptr, 'r'}, + {"rulefile", required_argument, nullptr, 's'}, + {"tracefile", required_argument, nullptr, 't'}, + {"writefile", required_argument, nullptr, 'w'}, + {"version", no_argument, nullptr, 'v'}, + {"no-checksums", no_argument, nullptr, 'C'}, + {"force-dns", no_argument, nullptr, 'F'}, + {"load-seeds", required_argument, nullptr, 'G'}, + {"save-seeds", required_argument, nullptr, 'H'}, + {"print-plugins", no_argument, nullptr, 'N'}, + {"prime-dns", no_argument, nullptr, 'P'}, + {"time", no_argument, nullptr, 'Q'}, + {"debug-rules", no_argument, nullptr, 'S'}, + {"re-level", required_argument, nullptr, 'T'}, + {"watchdog", no_argument, nullptr, 'W'}, + {"print-id", required_argument, nullptr, 'I'}, + {"status-file", required_argument, nullptr, 'U'}, #ifdef DEBUG - {"debug", required_argument, 0, 'B'}, + {"debug", required_argument, nullptr, 'B'}, #endif #ifdef USE_IDMEF - {"idmef-dtd", required_argument, 0, 'n'}, + {"idmef-dtd", required_argument, nullptr, 'n'}, #endif #ifdef USE_PERFTOOLS_DEBUG - {"mem-leaks", no_argument, 0, 'm'}, - {"mem-profile", no_argument, 0, 'M'}, + {"mem-leaks", no_argument, nullptr, 'm'}, + {"mem-profile", no_argument, nullptr, 'M'}, #endif - {"pseudo-realtime", optional_argument, 0, 'E'}, - {"jobs", optional_argument, 0, 'j'}, - {"test", no_argument, 0, '#'}, + {"pseudo-realtime", optional_argument, nullptr, 'E'}, + {"jobs", optional_argument, nullptr, 'j'}, + {"test", no_argument, nullptr, '#'}, - {0, 0, 0, 0}, + {nullptr, 0, nullptr, 0}, }; char opts[256]; diff --git a/src/PolicyFile.cc b/src/PolicyFile.cc index a6f93c8d88..470194b3a1 100644 --- a/src/PolicyFile.cc +++ b/src/PolicyFile.cc @@ -18,8 +18,8 @@ using namespace std; #include "Reporter.h" struct PolicyFile { - PolicyFile () { filedata = 0; lmtime = 0; } - ~PolicyFile () { delete [] filedata; filedata = 0; } + PolicyFile () { filedata = nullptr; lmtime = 0; } + ~PolicyFile () { delete [] filedata; filedata = nullptr; } time_t lmtime; char* filedata; diff --git a/src/PrefixTable.cc b/src/PrefixTable.cc index 391d11e673..36012af5a3 100644 --- a/src/PrefixTable.cc +++ b/src/PrefixTable.cc @@ -28,7 +28,7 @@ void* PrefixTable::Insert(const IPAddr& addr, int width, void* data) if ( ! node ) { reporter->InternalWarning("Cannot create node in patricia tree"); - return 0; + return nullptr; } void* old = node->data; @@ -59,7 +59,7 @@ void* PrefixTable::Insert(const Val* value, void* data) default: reporter->InternalWarning("Wrong index type for PrefixTable"); - return 0; + return nullptr; } } @@ -97,7 +97,7 @@ void* PrefixTable::Lookup(const IPAddr& addr, int width, bool exact) const patricia_node_t** list = nullptr; Deref_Prefix(prefix); - return node ? node->data : 0; + return node ? node->data : nullptr; } void* PrefixTable::Lookup(const Val* value, bool exact) const @@ -120,7 +120,7 @@ void* PrefixTable::Lookup(const Val* value, bool exact) const default: reporter->InternalWarning("Wrong index type %d for PrefixTable", value->Type()->Tag()); - return 0; + return nullptr; } } @@ -131,7 +131,7 @@ void* PrefixTable::Remove(const IPAddr& addr, int width) Deref_Prefix(prefix); if ( ! node ) - return 0; + return nullptr; void* old = node->data; patricia_remove(tree, node); @@ -158,7 +158,7 @@ void* PrefixTable::Remove(const Val* value) default: reporter->InternalWarning("Wrong index type for PrefixTable"); - return 0; + return nullptr; } } @@ -167,7 +167,7 @@ PrefixTable::iterator PrefixTable::InitIterator() iterator i; i.Xsp = i.Xstack; i.Xrn = tree->head; - i.Xnode = 0; + i.Xnode = nullptr; return i; } @@ -177,7 +177,7 @@ void* PrefixTable::GetNext(iterator* i) { i->Xnode = i->Xrn; if ( ! i->Xnode ) - return 0; + return nullptr; if ( i->Xrn->l ) { @@ -194,7 +194,7 @@ void* PrefixTable::GetNext(iterator* i) i->Xrn = *(--i->Xsp); else - i->Xrn = (patricia_node_t*) 0; + i->Xrn = (patricia_node_t*) nullptr; if ( i->Xnode->prefix ) return (void*) i->Xnode->data; diff --git a/src/PrefixTable.h b/src/PrefixTable.h index 21b956756a..2bd640772d 100644 --- a/src/PrefixTable.h +++ b/src/PrefixTable.h @@ -30,10 +30,10 @@ public: // Addr in network byte order. If data is zero, acts like a set. // Returns ptr to old data if already existing. // For existing items without data, returns non-nil if found. - void* Insert(const IPAddr& addr, int width, void* data = 0); + void* Insert(const IPAddr& addr, int width, void* data = nullptr); // Value may be addr or subnet. - void* Insert(const Val* value, void* data = 0); + void* Insert(const Val* value, void* data = nullptr); // Returns nil if not found, pointer to data otherwise. // For items without data, returns non-nil if found. diff --git a/src/PriorityQueue.h b/src/PriorityQueue.h index 05de50ee69..591c79c474 100644 --- a/src/PriorityQueue.h +++ b/src/PriorityQueue.h @@ -34,7 +34,7 @@ public: PQ_Element* Top() const { if ( heap_size == 0 ) - return 0; + return nullptr; return heap[0]; } diff --git a/src/RE.cc b/src/RE.cc index 183c421e17..ac59567f4d 100644 --- a/src/RE.cc +++ b/src/RE.cc @@ -12,10 +12,10 @@ #include "Reporter.h" #include "BroString.h" -CCL* curr_ccl = 0; +CCL* curr_ccl = nullptr; Specific_RE_Matcher* rem; -NFA_Machine* nfa = 0; +NFA_Machine* nfa = nullptr; int case_insensitive = 0; extern int RE_parse(void); @@ -27,10 +27,10 @@ Specific_RE_Matcher::Specific_RE_Matcher(match_type arg_mt, int arg_multiline) { mt = arg_mt; multiline = arg_multiline; - any_ccl = 0; - pattern_text = 0; - dfa = 0; - ecs = 0; + any_ccl = nullptr; + pattern_text = nullptr; + dfa = nullptr; + ecs = nullptr; accepted = new AcceptingSet(); } @@ -131,7 +131,7 @@ bool Specific_RE_Matcher::Compile(bool lazy) { reporter->Error("error compiling pattern /%s/", pattern_text); Unref(nfa); - nfa = 0; + nfa = nullptr; return false; } @@ -141,7 +141,7 @@ bool Specific_RE_Matcher::Compile(bool lazy) dfa = new DFA_Machine(nfa, EC()); Unref(nfa); - nfa = 0; + nfa = nullptr; ecs = EC()->EquivClasses(); @@ -155,7 +155,7 @@ bool Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx rem = this; - NFA_Machine* set_nfa = 0; + NFA_Machine* set_nfa = nullptr; loop_over_list(set, i) { @@ -172,7 +172,7 @@ bool Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx else Unref(nfa); - nfa = 0; + nfa = nullptr; return false; } @@ -257,7 +257,7 @@ bool Specific_RE_Matcher::MatchAll(const u_char* bv, int n) if ( d ) d = d->Xtion(ecs[SYM_EOL], dfa); - return d && d->Accept() != 0; + return d && d->Accept() != nullptr; } @@ -354,7 +354,7 @@ bool RE_Match_State::Match(const u_char* bv, int n, if ( ! next_state ) { - current_state = 0; + current_state = nullptr; break; } diff --git a/src/RE.h b/src/RE.h index 702767016c..dfadcaaf28 100644 --- a/src/RE.h +++ b/src/RE.h @@ -140,10 +140,10 @@ class RE_Match_State { public: explicit RE_Match_State(Specific_RE_Matcher* matcher) { - dfa = matcher->DFA() ? matcher->DFA() : 0; + dfa = matcher->DFA() ? matcher->DFA() : nullptr; ecs = matcher->EC()->EquivClasses(); current_pos = -1; - current_state = 0; + current_state = nullptr; } const AcceptingMatchSet& AcceptedMatches() const @@ -159,7 +159,7 @@ public: void Clear() { current_pos = -1; - current_state = 0; + current_state = nullptr; accepted_matches.clear(); } diff --git a/src/Reporter.cc b/src/Reporter.cc index 68446dd553..ae5261ff5f 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -30,7 +30,7 @@ int closelog(); } #endif -Reporter* reporter = 0; +Reporter* reporter = nullptr; Reporter::Reporter() { @@ -88,8 +88,8 @@ void Reporter::Info(const char* fmt, ...) { va_list ap; va_start(ap, fmt); - FILE* out = EmitToStderr(info_to_stderr) ? stderr : 0; - DoLog("", reporter_info, out, 0, 0, true, true, 0, fmt, ap); + FILE* out = EmitToStderr(info_to_stderr) ? stderr : nullptr; + DoLog("", reporter_info, out, nullptr, nullptr, true, true, nullptr, fmt, ap); va_end(ap); } @@ -97,8 +97,8 @@ void Reporter::Warning(const char* fmt, ...) { va_list ap; va_start(ap, fmt); - FILE* out = EmitToStderr(warnings_to_stderr) ? stderr : 0; - DoLog("warning", reporter_warning, out, 0, 0, true, true, 0, fmt, ap); + FILE* out = EmitToStderr(warnings_to_stderr) ? stderr : nullptr; + DoLog("warning", reporter_warning, out, nullptr, nullptr, true, true, nullptr, fmt, ap); va_end(ap); } @@ -107,8 +107,8 @@ void Reporter::Error(const char* fmt, ...) ++errors; va_list ap; va_start(ap, fmt); - FILE* out = EmitToStderr(errors_to_stderr) ? stderr : 0; - DoLog("error", reporter_error, out, 0, 0, true, true, 0, fmt, ap); + FILE* out = EmitToStderr(errors_to_stderr) ? stderr : nullptr; + DoLog("error", reporter_error, out, nullptr, nullptr, true, true, nullptr, fmt, ap); va_end(ap); } @@ -118,7 +118,7 @@ void Reporter::FatalError(const char* fmt, ...) va_start(ap, fmt); // Always log to stderr. - DoLog("fatal error", 0, stderr, 0, 0, true, false, 0, fmt, ap); + DoLog("fatal error", nullptr, stderr, nullptr, nullptr, true, false, nullptr, fmt, ap); va_end(ap); @@ -134,7 +134,7 @@ void Reporter::FatalErrorWithCore(const char* fmt, ...) va_start(ap, fmt); // Always log to stderr. - DoLog("fatal error", 0, stderr, 0, 0, true, false, 0, fmt, ap); + DoLog("fatal error", nullptr, stderr, nullptr, nullptr, true, false, nullptr, fmt, ap); va_end(ap); @@ -152,8 +152,8 @@ void Reporter::ExprRuntimeError(const Expr* expr, const char* fmt, ...) PushLocation(expr->GetLocationInfo()); va_list ap; va_start(ap, fmt); - FILE* out = EmitToStderr(errors_to_stderr) ? stderr : 0; - DoLog("expression error", reporter_error, out, 0, 0, true, true, + FILE* out = EmitToStderr(errors_to_stderr) ? stderr : nullptr; + DoLog("expression error", reporter_error, out, nullptr, nullptr, true, true, d.Description(), fmt, ap); va_end(ap); PopLocation(); @@ -166,8 +166,8 @@ void Reporter::RuntimeError(const Location* location, const char* fmt, ...) PushLocation(location); va_list ap; va_start(ap, fmt); - FILE* out = EmitToStderr(errors_to_stderr) ? stderr : 0; - DoLog("runtime error", reporter_error, out, 0, 0, true, true, "", fmt, ap); + FILE* out = EmitToStderr(errors_to_stderr) ? stderr : nullptr; + DoLog("runtime error", reporter_error, out, nullptr, nullptr, true, true, "", fmt, ap); va_end(ap); PopLocation(); throw InterpreterException(); @@ -179,7 +179,7 @@ void Reporter::InternalError(const char* fmt, ...) va_start(ap, fmt); // Always log to stderr. - DoLog("internal error", 0, stderr, 0, 0, true, false, 0, fmt, ap); + DoLog("internal error", nullptr, stderr, nullptr, nullptr, true, false, nullptr, fmt, ap); va_end(ap); @@ -197,7 +197,7 @@ void Reporter::AnalyzerError(analyzer::Analyzer* a, const char* fmt, va_start(ap, fmt); // Always log to stderr. // TODO: would be nice to also log a call stack. - DoLog("analyzer error", reporter_error, stderr, 0, 0, true, true, 0, fmt, + DoLog("analyzer error", reporter_error, stderr, nullptr, nullptr, true, true, nullptr, fmt, ap); va_end(ap); } @@ -206,9 +206,9 @@ void Reporter::InternalWarning(const char* fmt, ...) { va_list ap; va_start(ap, fmt); - FILE* out = EmitToStderr(warnings_to_stderr) ? stderr : 0; + FILE* out = EmitToStderr(warnings_to_stderr) ? stderr : nullptr; // TODO: would be nice to also log a call stack. - DoLog("internal warning", reporter_warning, out, 0, 0, true, true, 0, fmt, + DoLog("internal warning", reporter_warning, out, nullptr, nullptr, true, true, nullptr, fmt, ap); va_end(ap); } @@ -228,7 +228,7 @@ void Reporter::WeirdHelper(EventHandlerPtr event, val_list vl, const char* fmt_n { va_list ap; va_start(ap, fmt_name); - DoLog("weird", event, 0, 0, &vl, false, false, 0, fmt_name, ap); + DoLog("weird", event, nullptr, nullptr, &vl, false, false, nullptr, fmt_name, ap); va_end(ap); } @@ -382,7 +382,7 @@ void Reporter::DoLog(const char* prefix, EventHandlerPtr event, FILE* out, int size = sizeof(tmp); char* buffer = tmp; - char* alloced = 0; + char* alloced = nullptr; string loc_str; diff --git a/src/Rule.cc b/src/Rule.cc index ade2ca3f7c..3a7533b6f6 100644 --- a/src/Rule.cc +++ b/src/Rule.cc @@ -87,7 +87,7 @@ void Rule::AddRequires(const char* id, bool opposite_direction, bool negate) { Precond* p = new Precond; p->id = copy_string(id); - p->rule = 0; + p->rule = nullptr; p->opposite_dir = opposite_direction; p->negate = negate; diff --git a/src/Rule.h b/src/Rule.h index 5d18ae8d84..29099dcb8e 100644 --- a/src/Rule.h +++ b/src/Rule.h @@ -25,7 +25,7 @@ public: idx = rule_counter++; location = arg_location; active = true; - next = 0; + next = nullptr; } ~Rule(); diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index f492846a4d..0abafcb4da 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -48,10 +48,10 @@ RuleHdrTest::RuleHdrTest(Prot arg_prot, uint32_t arg_offset, uint32_t arg_size, size = arg_size; comp = arg_comp; vals = arg_vals; - sibling = 0; - child = 0; - pattern_rules = 0; - pure_rules = 0; + sibling = nullptr; + child = nullptr; + pattern_rules = nullptr; + pure_rules = nullptr; ruleset = new IntSet; id = ++idcounter; level = 0; @@ -65,10 +65,10 @@ RuleHdrTest::RuleHdrTest(Prot arg_prot, Comp arg_comp, vector arg_v) comp = arg_comp; vals = new maskedvalue_list; prefix_vals = std::move(arg_v); - sibling = 0; - child = 0; - pattern_rules = 0; - pure_rules = 0; + sibling = nullptr; + child = nullptr; + pattern_rules = nullptr; + pure_rules = nullptr; ruleset = new IntSet; id = ++idcounter; level = 0; @@ -103,7 +103,7 @@ RuleHdrTest::RuleHdrTest(RuleHdrTest& h) for ( PatternSet* orig_set : h.psets[j] ) { PatternSet* copied_set = new PatternSet; - copied_set->re = 0; + copied_set->re = nullptr; copied_set->ids = orig_set->ids; for ( const auto& pattern : orig_set->patterns ) copied_set->patterns.push_back(copy_string(pattern)); @@ -113,10 +113,10 @@ RuleHdrTest::RuleHdrTest(RuleHdrTest& h) } } - sibling = 0; - child = 0; - pattern_rules = 0; - pure_rules = 0; + sibling = nullptr; + child = nullptr; + pattern_rules = nullptr; + pure_rules = nullptr; ruleset = new IntSet; id = ++idcounter; level = 0; @@ -758,8 +758,8 @@ RuleEndpointState* RuleMatcher::InitEndpoint(analyzer::Analyzer* analyzer, // Evaluate all rules on this node which don't contain // any patterns. for ( Rule* r = hdr_test->pure_rules; r; r = r->next ) - if ( EvalRuleConditions(r, state, 0, 0, false) ) - ExecRuleActions(r, state, 0, 0, false); + if ( EvalRuleConditions(r, state, nullptr, 0, false) ) + ExecRuleActions(r, state, nullptr, 0, false); // If we're on or above the RE_level, we may have some // pattern matching to do. @@ -989,7 +989,7 @@ void RuleMatcher::ExecPureRules(RuleEndpointState* state, bool eos) for ( const auto& hdr_test : state->hdr_tests ) { for ( Rule* r = hdr_test->pure_rules; r; r = r->next ) - ExecRulePurely(r, 0, state, eos); + ExecRulePurely(r, nullptr, state, eos); } } @@ -1001,14 +1001,14 @@ bool RuleMatcher::ExecRulePurely(Rule* r, BroString* s, DBG_LOG(DBG_RULES, "Checking rule %s purely", r->ID()); - if ( EvalRuleConditions(r, state, 0, 0, eos) ) + if ( EvalRuleConditions(r, state, nullptr, 0, eos) ) { DBG_LOG(DBG_RULES, "MATCH!"); if ( s ) ExecRuleActions(r, state, s->Bytes(), s->Len(), eos); else - ExecRuleActions(r, state, 0, 0, eos); + ExecRuleActions(r, state, nullptr, 0, eos); return true; } @@ -1098,7 +1098,7 @@ void RuleMatcher::ExecRule(Rule* rule, RuleEndpointState* state, bool eos) for ( Rule* r = h->pure_rules; r; r = r->next ) if ( r == rule ) { // found, so let's evaluate it - ExecRulePurely(rule, 0, state, eos); + ExecRulePurely(rule, nullptr, state, eos); return; } @@ -1273,7 +1273,7 @@ static Val* get_bro_val(const char* label) if ( ! id ) { rules_error("unknown script-level identifier", label); - return 0; + return nullptr; } return id->ID_Val(); @@ -1464,7 +1464,7 @@ void RuleMatcherState::FinishEndpointMatcher() delete orig_match_state; delete resp_match_state; - orig_match_state = resp_match_state = 0; + orig_match_state = resp_match_state = nullptr; } void RuleMatcherState::Match(Rule::PatternType type, const u_char* data, diff --git a/src/RuleMatcher.h b/src/RuleMatcher.h index 0650081000..4e4845cecf 100644 --- a/src/RuleMatcher.h +++ b/src/RuleMatcher.h @@ -67,7 +67,7 @@ typedef PList bstr_list; // Get values from Bro's script-level variables. extern void id_to_maskedvallist(const char* id, maskedvalue_list* append_to, - vector* prefix_vector = 0); + vector* prefix_vector = nullptr); extern char* id_to_str(const char* id); extern uint32_t id_to_uint(const char* id); @@ -256,7 +256,7 @@ public: * @return The results of the signature matching. */ MIME_Matches* Match(RuleFileMagicState* state, const u_char* data, - uint64_t len, MIME_Matches* matches = 0) const; + uint64_t len, MIME_Matches* matches = nullptr) const; /** @@ -313,7 +313,7 @@ public: Val* BuildRuleStateValue(const Rule* rule, const RuleEndpointState* state) const; - void GetStats(Stats* stats, RuleHdrTest* hdr_test = 0); + void GetStats(Stats* stats, RuleHdrTest* hdr_test = nullptr); void DumpStats(BroFile* f); private: @@ -373,13 +373,13 @@ private: // Keeps bi-directional matching-state. class RuleMatcherState { public: - RuleMatcherState() { orig_match_state = resp_match_state = 0; } + RuleMatcherState() { orig_match_state = resp_match_state = nullptr; } ~RuleMatcherState() { delete orig_match_state; delete resp_match_state; } // ip may be nil. void InitEndpointMatcher(analyzer::Analyzer* analyzer, const IP_Hdr* ip, - int caplen, bool from_orig, analyzer::pia::PIA* pia = 0); + int caplen, bool from_orig, analyzer::pia::PIA* pia = nullptr); // bol/eol should be set to false for type Rule::PAYLOAD; they're // deduced automatically. diff --git a/src/Scope.cc b/src/Scope.cc index c75dc64410..c324c6a134 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -20,7 +20,7 @@ Scope::Scope(IntrusivePtr id, attr_list* al) : scope_id(std::move(id)) { attrs = al; - return_type = 0; + return_type = nullptr; inits = new id_list; @@ -65,7 +65,7 @@ ID* Scope::GenerateTemporary(const char* name) id_list* Scope::GetInits() { id_list* ids = inits; - inits = 0; + inits = nullptr; return ids; } @@ -76,9 +76,9 @@ void Scope::Describe(ODesc* d) const else { - d->Add(scope_id != 0); + d->Add(scope_id != nullptr); d->SP(); - d->Add(return_type != 0); + d->Add(return_type != nullptr); d->SP(); d->Add(static_cast(local.size())); d->SP(); @@ -149,7 +149,7 @@ IntrusivePtr lookup_ID(const char* name, const char* curr_module, return {NewRef{}, id}; } - return 0; + return nullptr; } IntrusivePtr install_ID(const char* name, const char* module_name, diff --git a/src/SerializationFormat.cc b/src/SerializationFormat.cc index 1aa8346f3f..f2dd26bf5b 100644 --- a/src/SerializationFormat.cc +++ b/src/SerializationFormat.cc @@ -29,7 +29,7 @@ void SerializationFormat::StartRead(const char* data, uint32_t arg_len) void SerializationFormat::EndRead() { - input = 0; + input = nullptr; } void SerializationFormat::StartWrite() @@ -37,7 +37,7 @@ void SerializationFormat::StartWrite() if ( output && output_size > INITIAL_SIZE ) { free(output); - output = 0; + output = nullptr; } if ( ! output ) @@ -54,7 +54,7 @@ uint32_t SerializationFormat::EndWrite(char** data) { uint32_t rval = output_pos; *data = output; - output = 0; + output = nullptr; output_size = 0; output_pos = 0; return rval; @@ -193,7 +193,7 @@ bool BinarySerializationFormat::Read(char** str, int* len, const char* tag) if ( ! ReadData(s, l) ) { delete [] s; - *str = 0; + *str = nullptr; return false; } diff --git a/src/Sessions.cc b/src/Sessions.cc index ba40f08cad..104a39f28e 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -68,16 +68,16 @@ NetSessions::NetSessions() if ( stp_correlate_pair ) stp_manager = new analyzer::stepping_stone::SteppingStoneManager(); else - stp_manager = 0; + stp_manager = nullptr; discarder = new Discarder(); if ( ! discarder->IsActive() ) { delete discarder; - discarder = 0; + discarder = nullptr; } - packet_filter = 0; + packet_filter = nullptr; dump_this_packet = false; num_packets_processed = 0; @@ -86,12 +86,12 @@ NetSessions::NetSessions() pkt_profiler = new PacketProfiler(pkt_profile_mode, pkt_profile_freq, pkt_profile_file->AsFile()); else - pkt_profiler = 0; + pkt_profiler = nullptr; if ( arp_request || arp_reply || bad_arp ) arp_analyzer = new analyzer::arp::ARP_Analyzer(); else - arp_analyzer = 0; + arp_analyzer = nullptr; memset(&stats, 0, sizeof(SessionStats)); } @@ -153,7 +153,7 @@ void NetSessions::NextPacket(double t, const Packet* pkt) const struct ip* ip = (const struct ip*) (pkt->data + pkt->hdr_size); IP_Hdr ip_hdr(ip, false); - DoNextPacket(t, pkt, &ip_hdr, 0); + DoNextPacket(t, pkt, &ip_hdr, nullptr); } else if ( pkt->l3_proto == L3_IPV6 ) @@ -165,7 +165,7 @@ void NetSessions::NextPacket(double t, const Packet* pkt) } IP_Hdr ip_hdr((const struct ip6_hdr*) (pkt->data + pkt->hdr_size), false, caplen); - DoNextPacket(t, pkt, &ip_hdr, 0); + DoNextPacket(t, pkt, &ip_hdr, nullptr); } else if ( pkt->l3_proto == L3_ARP ) @@ -261,7 +261,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr if ( discarder && discarder->NextPacket(ip_hdr, len, caplen) ) return; - FragReassembler* f = 0; + FragReassembler* f = nullptr; if ( ip_hdr->IsFragment() ) { @@ -574,7 +574,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr return; } - IP_Hdr* inner = 0; + IP_Hdr* inner = nullptr; if ( gre_version != 0 ) { @@ -662,7 +662,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr // We already know that connection. if ( conn->IsReuse(t, data) ) { - conn->Event(connection_reused, 0); + conn->Event(connection_reused, nullptr); Remove(conn); conn = NewConn(key, t, &id, data, proto, ip_hdr->FlowLabel(), pkt, encapsulation); @@ -686,16 +686,16 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr conn->CheckFlowLabel(is_orig, ip_hdr->FlowLabel()); - Val* pkt_hdr_val = 0; + Val* pkt_hdr_val = nullptr; if ( ipv6_ext_headers && ip_hdr->NumHeaders() > 1 ) { pkt_hdr_val = ip_hdr->BuildPktHdrVal(); - conn->Event(ipv6_ext_headers, 0, pkt_hdr_val); + conn->Event(ipv6_ext_headers, nullptr, pkt_hdr_val); } if ( new_packet ) - conn->Event(new_packet, 0, + conn->Event(new_packet, nullptr, pkt_hdr_val ? pkt_hdr_val->Ref() : ip_hdr->BuildPktHdrVal()); conn->NextPacket(t, is_orig, ip_hdr, len, caplen, data, @@ -739,7 +739,7 @@ void NetSessions::DoNextInnerPacket(double t, const Packet* pkt, ((network_time - (double)ts.tv_sec) * 1000000); } - const u_char* data = 0; + const u_char* data = nullptr; if ( inner->IP4_Hdr() ) data = (const u_char*) inner->IP4_Hdr(); @@ -906,7 +906,7 @@ Connection* NetSessions::FindConnection(Val* v) { BroType* vt = v->Type(); if ( ! IsRecord(vt->Tag()) ) - return 0; + return nullptr; RecordType* vr = vt->AsRecordType(); const val_list* vl = v->AsRecord(); @@ -931,7 +931,7 @@ Connection* NetSessions::FindConnection(Val* v) resp_p = vr->FieldOffset("resp_p"); if ( orig_h < 0 || resp_h < 0 || orig_p < 0 || resp_p < 0 ) - return 0; + return nullptr; // ### we ought to check that the fields have the right // types, too. @@ -967,7 +967,7 @@ Connection* NetSessions::FindConnection(Val* v) // This can happen due to pseudo-connections we // construct, for example for packet headers embedded // in ICMPs. - return 0; + return nullptr; } Connection* conn = nullptr; @@ -1151,7 +1151,7 @@ Connection* NetSessions::NewConn(const ConnIDKey& k, double t, const ConnID* id, break; default: reporter->InternalWarning("unknown transport protocol"); - return 0; + return nullptr; }; if ( tproto == TRANSPORT_TCP ) @@ -1163,7 +1163,7 @@ Connection* NetSessions::NewConn(const ConnIDKey& k, double t, const ConnID* id, bool flip = false; if ( ! WantConnection(src_h, dst_h, tproto, flags, flip) ) - return 0; + return nullptr; Connection* conn = new Connection(this, k, t, id, flow_label, pkt, encapsulation); conn->SetTransport(tproto); @@ -1175,11 +1175,11 @@ Connection* NetSessions::NewConn(const ConnIDKey& k, double t, const ConnID* id, { conn->Done(); Unref(conn); - return 0; + return nullptr; } if ( new_connection ) - conn->Event(new_connection, 0); + conn->Event(new_connection, nullptr); return conn; } diff --git a/src/Sessions.h b/src/Sessions.h index efa4e430a2..8d67df1d96 100644 --- a/src/Sessions.h +++ b/src/Sessions.h @@ -75,9 +75,9 @@ public: void GetStats(SessionStats& s) const; void Weird(const char* name, const Packet* pkt, - const EncapsulationStack* encap = 0, const char* addl = ""); + const EncapsulationStack* encap = nullptr, const char* addl = ""); void Weird(const char* name, const IP_Hdr* ip, - const EncapsulationStack* encap = 0, const char* addl = ""); + const EncapsulationStack* encap = nullptr, const char* addl = ""); PacketFilter* GetPacketFilter() { diff --git a/src/SmithWaterman.cc b/src/SmithWaterman.cc index 31611d1d4a..c9896d3c19 100644 --- a/src/SmithWaterman.cc +++ b/src/SmithWaterman.cc @@ -61,22 +61,22 @@ VectorVal* BroSubstring::VecToPolicy(Vec* vec) RecordType* sw_substring_type = internal_type("sw_substring")->AsRecordType(); if ( ! sw_substring_type ) - return 0; + return nullptr; RecordType* sw_align_type = internal_type("sw_align")->AsRecordType(); if ( ! sw_align_type ) - return 0; + return nullptr; VectorType* sw_align_vec_type = internal_type("sw_align_vec")->AsVectorType(); if ( ! sw_align_vec_type ) - return 0; + return nullptr; VectorVal* result = new VectorVal(internal_type("sw_substring_vec")->AsVectorType()); if ( ! result ) - return 0; + return nullptr; if ( vec ) { @@ -235,9 +235,9 @@ public: { // Make sure access is in allowed range. if ( row < 0 || row >= _rows ) - return 0; + return nullptr; if ( col < 0 || col >= _cols ) - return 0; + return nullptr; return &(_nodes[row * _cols + col]); } @@ -359,7 +359,7 @@ static void sw_collect_multiple(BroSubstring::Vec* result, { BroSubstring::Vec* old_al = *it; - if ( old_al == 0 ) + if ( old_al == nullptr ) continue; for ( BroSubstring::VecIt it2 = old_al->begin(); @@ -372,7 +372,7 @@ static void sw_collect_multiple(BroSubstring::Vec* result, { delete_each(new_al); delete new_al; - new_al = 0; + new_al = nullptr; goto end_loop; } @@ -398,7 +398,7 @@ end_loop: { BroSubstring::Vec* al = *it; - if ( al == 0 ) + if ( al == nullptr ) continue; for ( BroSubstring::VecIt it2 = al->begin(); @@ -432,8 +432,8 @@ BroSubstring::Vec* smith_waterman(const BroString* s1, const BroString* s2, byte_vec string2 = s2->Bytes(); SWNodeMatrix matrix(s1, s2); // dynamic programming matrix. - SWNode* node_max = 0; // pointer to the best score's node - SWNode* node_br_max = 0; // pointer to lowest-right matching node + SWNode* node_max = nullptr; // pointer to the best score's node + SWNode* node_br_max = nullptr; // pointer to lowest-right matching node // The highest score in the matrix, globally. We initialize to 1 // because we are only interested in real scores (initializing to diff --git a/src/Stats.cc b/src/Stats.cc index 8720933fae..8ab8a21cbc 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -339,7 +339,7 @@ void ProfileLogger::SegmentProfile(const char* name, const Location* loc, SampleLogger::SampleLogger() { - static TableType* load_sample_info = 0; + static TableType* load_sample_info = nullptr; if ( ! load_sample_info ) load_sample_info = internal_type("load_sample_info")->AsTableType(); @@ -355,14 +355,14 @@ SampleLogger::~SampleLogger() void SampleLogger::FunctionSeen(const Func* func) { Val* idx = new StringVal(func->Name()); - load_samples->Assign(idx, 0); + load_samples->Assign(idx, nullptr); Unref(idx); } void SampleLogger::LocationSeen(const Location* loc) { Val* idx = new StringVal(loc->filename); - load_samples->Assign(idx, 0); + load_samples->Assign(idx, nullptr); Unref(idx); } @@ -438,7 +438,7 @@ void PacketProfiler::ProfilePkt(double t, unsigned int bytes) getrusage(RUSAGE_SELF, &res); gettimeofday(&ptimestamp, 0); - get_memory_usage(&last_mem, 0); + get_memory_usage(&last_mem, nullptr); last_Utime = res.ru_utime.tv_sec + res.ru_utime.tv_usec / 1e6; last_Stime = res.ru_stime.tv_sec + res.ru_stime.tv_usec / 1e6; last_Rtime = ptimestamp.tv_sec + ptimestamp.tv_usec / 1e6; @@ -462,7 +462,7 @@ void PacketProfiler::ProfilePkt(double t, unsigned int bytes) ptimestamp.tv_sec + ptimestamp.tv_usec / 1e6; uint64_t curr_mem; - get_memory_usage(&curr_mem, 0); + get_memory_usage(&curr_mem, nullptr); file->Write(fmt("%.06f %.03f %" PRIu64 " %" PRIu64 " %.03f %.03f %.03f %" PRIu64 "\n", t, time-last_timestamp, pkt_cnt, byte_cnt, diff --git a/src/Stmt.cc b/src/Stmt.cc index 0a7e0cdcae..5b2a7023ba 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -182,7 +182,7 @@ TraversalCode ExprListStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -static BroFile* print_stdout = 0; +static BroFile* print_stdout = nullptr; static IntrusivePtr lookup_enum_val(const char* module_name, const char* name) { @@ -629,7 +629,7 @@ SwitchStmt::SwitchStmt(IntrusivePtr index, case_list* arg_cases) NegExpr* ne = (NegExpr*)(expr); if ( ne->Op()->IsConst() ) - Unref(exprs.replace(j, new ConstExpr(ne->Eval(0)))); + Unref(exprs.replace(j, new ConstExpr(ne->Eval(nullptr)))); } break; @@ -638,7 +638,7 @@ SwitchStmt::SwitchStmt(IntrusivePtr index, case_list* arg_cases) PosExpr* pe = (PosExpr*)(expr); if ( pe->Op()->IsConst() ) - Unref(exprs.replace(j, new ConstExpr(pe->Eval(0)))); + Unref(exprs.replace(j, new ConstExpr(pe->Eval(nullptr)))); } break; @@ -648,7 +648,7 @@ SwitchStmt::SwitchStmt(IntrusivePtr index, case_list* arg_cases) if ( ne->Id()->IsConst() ) { - auto v = ne->Eval(0); + auto v = ne->Eval(nullptr); if ( v ) Unref(exprs.replace(j, new ConstExpr(std::move(v)))); @@ -757,7 +757,7 @@ bool SwitchStmt::AddCaseLabelTypeMapping(ID* t, int idx) std::pair SwitchStmt::FindCaseLabelMatch(const Val* v) const { int label_idx = -1; - ID* label_id = 0; + ID* label_id = nullptr; // Find matching expression cases. if ( case_label_value_map.Length() ) @@ -1065,7 +1065,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) : ExprStmt(STMT_FOR, std::move(loop_expr)) { loop_vars = arg_loop_vars; - body = 0; + body = nullptr; if ( e->Type()->Tag() == TYPE_TABLE ) { @@ -1090,7 +1090,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) { add_local({NewRef{}, (*loop_vars)[i]}, {NewRef{}, ind_type}, INIT_NONE, - 0, 0, VAR_REGULAR); + nullptr, nullptr, VAR_REGULAR); } } } @@ -1106,7 +1106,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) BroType* t = (*loop_vars)[0]->Type(); if ( ! t ) add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_COUNT), - INIT_NONE, 0, 0, VAR_REGULAR); + INIT_NONE, nullptr, nullptr, VAR_REGULAR); else if ( ! IsIntegral(t->Tag()) ) { @@ -1127,7 +1127,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr loop_expr) if ( ! t ) add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_STRING), - INIT_NONE, 0, 0, VAR_REGULAR); + INIT_NONE, nullptr, nullptr, VAR_REGULAR); else if ( t->Tag() != TYPE_STRING ) { @@ -1158,7 +1158,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, else { add_local(value_var, {NewRef{}, yield_type}, INIT_NONE, - 0, 0, VAR_REGULAR); + nullptr, nullptr, VAR_REGULAR); } } else @@ -1471,7 +1471,7 @@ void ReturnStmt::Describe(ODesc* d) const { Stmt::Describe(d); if ( ! d->IsReadable() ) - d->Add(e != 0); + d->Add(e != nullptr); if ( e ) { @@ -1600,7 +1600,7 @@ IntrusivePtr EventBodyList::Exec(Frame* f, stmt_flow_type& flow) const // Simulate a return so the hooks operate properly. stmt_flow_type ft = FLOW_RETURN; - (void) post_execute_stmt(f->GetNextStmt(), f, 0, &ft); + (void) post_execute_stmt(f->GetNextStmt(), f, nullptr, &ft); return nullptr; } @@ -1656,7 +1656,7 @@ IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const { BroType* t = aggr->Type(); - Val* v = 0; + Val* v = nullptr; switch ( t->Tag() ) { case TYPE_RECORD: diff --git a/src/Tag.cc b/src/Tag.cc index f09b06c054..e0145afd6d 100644 --- a/src/Tag.cc +++ b/src/Tag.cc @@ -41,13 +41,13 @@ Tag::Tag() { type = 0; subtype = 0; - val = 0; + val = nullptr; } Tag::~Tag() { Unref(val); - val = 0; + val = nullptr; } Tag& Tag::operator=(const Tag& other) diff --git a/src/Traverse.h b/src/Traverse.h index 2ef672ddd7..2e528905e0 100644 --- a/src/Traverse.h +++ b/src/Traverse.h @@ -12,7 +12,7 @@ class ID; class TraversalCallback { public: - TraversalCallback() { current_scope = 0; } + TraversalCallback() { current_scope = nullptr; } virtual ~TraversalCallback() {} virtual TraversalCode PreFunction(const Func*) { return TC_CONTINUE; } diff --git a/src/Trigger.cc b/src/Trigger.cc index d3b11e5cd8..773ae78c23 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -130,10 +130,10 @@ Trigger::Trigger(Expr* arg_cond, Stmt* arg_body, Stmt* arg_timeout_stmts, timeout_stmts = arg_timeout_stmts; timeout = arg_timeout; frame = arg_frame->Clone(); - timer = 0; + timer = nullptr; delayed = false; disabled = false; - attached = 0; + attached = nullptr; is_return = arg_is_return; location = arg_location; timeout_value = -1; diff --git a/src/TunnelEncapsulation.h b/src/TunnelEncapsulation.h index 4f18b6118b..9dbf169326 100644 --- a/src/TunnelEncapsulation.h +++ b/src/TunnelEncapsulation.h @@ -129,7 +129,7 @@ protected: */ class EncapsulationStack { public: - EncapsulationStack() : conns(0) + EncapsulationStack() : conns(nullptr) {} EncapsulationStack(const EncapsulationStack& other) @@ -137,7 +137,7 @@ public: if ( other.conns ) conns = new vector(*(other.conns)); else - conns = 0; + conns = nullptr; } EncapsulationStack& operator=(const EncapsulationStack& other) @@ -150,7 +150,7 @@ public: if ( other.conns ) conns = new vector(*(other.conns)); else - conns = 0; + conns = nullptr; return *this; } diff --git a/src/Type.cc b/src/Type.cc index baa1b6552a..a55781c648 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -541,7 +541,7 @@ void FuncType::Describe(ODesc* d) const { d->Add(int(Tag())); d->Add(flavor); - d->Add(yield != 0); + d->Add(yield != nullptr); args->DescribeFields(d); if ( yield ) yield->Describe(d); @@ -648,7 +648,7 @@ bool RecordType::HasField(const char* field) const BroType* RecordType::FieldType(const char* field) const { int offset = FieldOffset(field); - return offset >= 0 ? FieldType(offset) : 0; + return offset >= 0 ? FieldType(offset) : nullptr; } BroType* RecordType::FieldType(int field) const @@ -783,7 +783,7 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const if ( fv ) ::Ref(fv); - bool logged = (fd->attrs && fd->FindAttr(ATTR_LOG) != 0); + bool logged = (fd->attrs && fd->FindAttr(ATTR_LOG) != nullptr); auto nr = make_intrusive(internal_type("record_field")->AsRecordType()); @@ -1575,10 +1575,10 @@ bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_re bool same_attrs(const Attributes* a1, const Attributes* a2) { if ( ! a1 ) - return (a2 == 0); + return (a2 == nullptr); if ( ! a2 ) - return (a1 == 0); + return (a1 == nullptr); return (*a1 == *a2); } @@ -2023,7 +2023,7 @@ IntrusivePtr init_type(Expr* init) // Could be a record, a set, or a list of table elements. Expr* e0 = el[0]; - if ( e0->IsRecordElement(0) ) + if ( e0->IsRecordElement(nullptr) ) // ListExpr's know how to build a record from their // components. return init_list->InitType(); @@ -2039,7 +2039,7 @@ IntrusivePtr init_type(Expr* init) for ( int i = 1; t && i < el.length(); ++i ) { auto el_t = el[i]->InitType(); - BroType* ti = el_t ? reduce_type(el_t.get()) : 0; + BroType* ti = el_t ? reduce_type(el_t.get()) : nullptr; if ( ! ti ) return nullptr; diff --git a/src/Type.h b/src/Type.h index 9686bcdf9f..a201c8ce3c 100644 --- a/src/Type.h +++ b/src/Type.h @@ -304,12 +304,12 @@ public: bool IsSet() const { - return tag == TYPE_TABLE && (YieldType() == 0); + return tag == TYPE_TABLE && (YieldType() == nullptr); } bool IsTable() const { - return tag == TYPE_TABLE && (YieldType() != 0); + return tag == TYPE_TABLE && (YieldType() != nullptr); } BroType* Ref() { ::Ref(this); return this; } @@ -357,7 +357,7 @@ public: const type_list* Types() const { return &types; } type_list* Types() { return &types; } - bool IsPure() const { return pure_type != 0; } + bool IsPure() const { return pure_type != nullptr; } // Returns the underlying pure type, or nil if the list // is not pure or is empty. @@ -485,12 +485,12 @@ protected: class TypeDecl final { public: - TypeDecl(IntrusivePtr t, const char* i, attr_list* attrs = 0, bool in_record = false); + TypeDecl(IntrusivePtr t, const char* i, attr_list* attrs = nullptr, bool in_record = false); TypeDecl(const TypeDecl& other); ~TypeDecl(); const Attr* FindAttr(attr_tag a) const - { return attrs ? attrs->FindAttr(a) : 0; } + { return attrs ? attrs->FindAttr(a) : nullptr; } void DescribeReST(ODesc* d, bool roles_only = false) const; @@ -547,19 +547,19 @@ public: bool IsFieldDeprecated(int field) const { const TypeDecl* decl = FieldDecl(field); - return decl && decl->FindAttr(ATTR_DEPRECATED) != 0; + return decl && decl->FindAttr(ATTR_DEPRECATED) != nullptr; } bool FieldHasAttr(int field, attr_tag at) const { const TypeDecl* decl = FieldDecl(field); - return decl && decl->FindAttr(at) != 0; + return decl && decl->FindAttr(at) != nullptr; } std::string GetFieldDeprecationWarning(int field, bool has_check) const; protected: - RecordType() { types = 0; } + RecordType() { types = nullptr; } int num_fields; type_decl_list* types; diff --git a/src/UID.h b/src/UID.h index 711541e283..68a87758e8 100644 --- a/src/UID.h +++ b/src/UID.h @@ -28,7 +28,7 @@ public: * Construct a UID of a given bit-length, optionally from given values. * @see UID::Set */ - explicit UID(bro_uint_t bits, const uint64_t* v = 0, size_t n = 0) + explicit UID(bro_uint_t bits, const uint64_t* v = nullptr, size_t n = 0) { Set(bits, v, n); } /** @@ -47,7 +47,7 @@ public: * 64, then a value is truncated to bit in desired bit-length. * @param n number of 64-bit elements in array pointed to by \a v. */ - void Set(bro_uint_t bits, const uint64_t* v = 0, size_t n = 0); + void Set(bro_uint_t bits, const uint64_t* v = nullptr, size_t n = 0); /** * Returns a base62 (characters 0-9, A-Z, a-z) representation of the UID. diff --git a/src/Val.cc b/src/Val.cc index 0597323b89..580ff4d58c 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -48,7 +48,7 @@ Val::Val(Func* f) static FileType* GetStringFileType() noexcept { - static FileType* string_file_type = 0; + static FileType* string_file_type = nullptr; if ( ! string_file_type ) string_file_type = new FileType(base_type(TYPE_STRING)); return string_file_type; @@ -366,13 +366,13 @@ void Val::ValDescribeReST(ODesc* d) const #ifdef DEBUG ID* Val::GetID() const { - return bound_id ? global_scope()->Lookup(bound_id) : 0; + return bound_id ? global_scope()->Lookup(bound_id) : nullptr; } void Val::SetID(ID* id) { delete [] bound_id; - bound_id = id ? copy_string(id->Name()) : 0; + bound_id = id ? copy_string(id->Name()) : nullptr; } #endif @@ -1233,7 +1233,7 @@ TableVal* ListVal::ConvertToSet() const TableVal* t = new TableVal(std::move(s)); for ( const auto& val : vals ) - t->Assign(val, 0); + t->Assign(val, nullptr); return t; } @@ -1381,16 +1381,16 @@ TableVal::TableVal(IntrusivePtr t, IntrusivePtr a) : Val( void TableVal::Init(IntrusivePtr t) { table_type = std::move(t); - expire_func = 0; - expire_time = 0; - expire_cookie = 0; - timer = 0; - def_val = 0; + expire_func = nullptr; + expire_time = nullptr; + expire_cookie = nullptr; + timer = nullptr; + def_val = nullptr; if ( table_type->IsSubNetIndex() ) subnets = new PrefixTable; else - subnets = 0; + subnets = nullptr; table_hash = new CompositeHash(IntrusivePtr(NewRef{}, table_type->Indices())); @@ -1603,12 +1603,12 @@ bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const if ( type->IsSet() ) { - if ( ! t->Assign(v->Value(), k, 0) ) + if ( ! t->Assign(v->Value(), k, nullptr) ) return false; } else { - if ( ! t->Assign(0, k, {NewRef{}, v->Value()}) ) + if ( ! t->Assign(nullptr, k, {NewRef{}, v->Value()}) ) return false; } } @@ -1804,11 +1804,11 @@ IntrusivePtr TableVal::Default(Val* index) auto coerce = make_intrusive( IntrusivePtr{NewRef{}, def_attr->AttrExpr()}, IntrusivePtr{NewRef{}, ytype->AsRecordType()}); - def_val = coerce->Eval(0); + def_val = coerce->Eval(nullptr); } else - def_val = def_attr->AttrExpr()->Eval(0); + def_val = def_attr->AttrExpr()->Eval(nullptr); } if ( ! def_val ) @@ -1942,7 +1942,7 @@ IntrusivePtr TableVal::LookupSubnetValues(const SubNetVal* search) if ( entry && entry->Value() ) nt->Assign(s, {NewRef{}, entry->Value()}); else - nt->Assign(s, 0); // set + nt->Assign(s, nullptr); // set if ( entry ) { @@ -2050,7 +2050,7 @@ void TableVal::CallChangeFunc(const Val* index, Val* old_value, OnChangeType tpe IntrusivePtr TableVal::Delete(const Val* index) { HashKey* k = ComputeHash(index); - TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : 0; + TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k) : nullptr; IntrusivePtr va{NewRef{}, v ? (v->Value() ? v->Value() : this) : nullptr}; if ( subnets && ! subnets->Remove(index) ) @@ -2128,7 +2128,7 @@ ListVal* TableVal::ConvertToPureList() const if ( tl->length() != 1 ) { InternalWarning("bad index type in TableVal::ConvertToPureList"); - return 0; + return nullptr; } return ConvertToList((*tl)[0]->Tag()); @@ -2136,7 +2136,7 @@ ListVal* TableVal::ConvertToPureList() const Attr* TableVal::FindAttr(attr_tag t) const { - return attrs ? attrs->FindAttr(t) : 0; + return attrs ? attrs->FindAttr(t) : nullptr; } void TableVal::Describe(ODesc* d) const @@ -2253,7 +2253,7 @@ bool TableVal::ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr new_ bool TableVal::CheckAndAssign(Val* index, IntrusivePtr new_val) { - Val* v = 0; + Val* v = nullptr; if ( subnets ) // We need an exact match here. v = (Val*) subnets->Lookup(index, true); @@ -2392,7 +2392,7 @@ void TableVal::DoExpire(double t) if ( ! v ) { - expire_cookie = 0; + expire_cookie = nullptr; InitTimer(table_expire_interval); } else @@ -2419,7 +2419,7 @@ double TableVal::GetExpireTime() if ( interval >= 0 ) return interval; - expire_time = 0; + expire_time = nullptr; if ( timer ) timer_mgr->Cancel(timer); @@ -2819,7 +2819,7 @@ IntrusivePtr RecordVal::CoerceTo(RecordType* t, bool allow_orphaning) if ( same_type(Type(), t) ) return {NewRef{}, this}; - return CoerceTo(t, 0, allow_orphaning); + return CoerceTo(t, nullptr, allow_orphaning); } IntrusivePtr RecordVal::GetRecordFieldsVal() const @@ -2975,7 +2975,7 @@ bool VectorVal::Assign(unsigned int index, IntrusivePtr element) ! same_type(element->Type(), vector_type->YieldType(), false) ) return false; - Val* val_at_index = 0; + Val* val_at_index = nullptr; if ( index < val.vector_val->size() ) val_at_index = (*val.vector_val)[index]; diff --git a/src/Val.h b/src/Val.h index 96b610892d..80bce5cb69 100644 --- a/src/Val.h +++ b/src/Val.h @@ -310,7 +310,7 @@ public: // To be overridden by mutable derived class to enable change // notification. - virtual notifier::Modifiable* Modifiable() { return 0; } + virtual notifier::Modifiable* Modifiable() { return nullptr; } #ifdef DEBUG // For debugging, we keep a reference to the global ID to which a @@ -804,7 +804,7 @@ public: void ClearTimer(Timer* t) { if ( timer == t ) - timer = 0; + timer = nullptr; } HashKey* ComputeHash(const Val* index) const; @@ -843,7 +843,7 @@ protected: IntrusivePtr Default(Val* index); // Returns true if item expiration is enabled. - bool ExpirationEnabled() { return expire_time != 0; } + bool ExpirationEnabled() { return expire_time != nullptr; } // Returns the expiration time defined by %{create,read,write}_expire // attribute, or -1 for unset/invalid values. In the invalid case, an diff --git a/src/Var.cc b/src/Var.cc index 406e8ab54b..ac1a0647fb 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -216,7 +216,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, // For events, add a function value (without any body) here so that // we can later access the ID even if no implementations have been // defined. - Func* f = new BroFunc(id, 0, 0, 0, 0); + Func* f = new BroFunc(id, nullptr, nullptr, 0, 0); id->SetVal(make_intrusive(f)); } } @@ -305,7 +305,7 @@ static void transfer_arg_defaults(RecordType* args, RecordType* recv) TypeDecl* args_i = args->FieldDecl(i); TypeDecl* recv_i = recv->FieldDecl(i); - Attr* def = args_i->attrs ? args_i->attrs->FindAttr(ATTR_DEFAULT) : 0; + Attr* def = args_i->attrs ? args_i->attrs->FindAttr(ATTR_DEFAULT) : nullptr; if ( ! def ) continue; @@ -379,7 +379,7 @@ void begin_func(ID* id, const char* module_name, function_flavor flavor, case FUNC_FLAVOR_HOOK: if ( is_redef ) // Clear out value so it will be replaced. - id->SetVal(0); + id->SetVal(nullptr); break; case FUNC_FLAVOR_FUNCTION: diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 79864ae86c..8c72ca7cc6 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -695,7 +695,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) auto rval = new RecordVal(BifType::Record::Broker::Event); auto arg_vec = new VectorVal(vector_of_data_type); rval->Assign(1, arg_vec); - Func* func = 0; + Func* func = nullptr; scoped_reporter_location srl{frame}; for ( auto i = 0; i < args->length(); ++i ) @@ -738,7 +738,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) if ( ! same_type(got_type, expected_type) ) { - rval->Assign(0, 0); + rval->Assign(0, nullptr); Error("event parameter #%d type mismatch, got %s, expect %s", i, type_name(got_type->Tag()), type_name(expected_type->Tag())); @@ -758,7 +758,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) if ( ! data_val->Lookup(0) ) { Unref(data_val); - rval->Assign(0, 0); + rval->Assign(0, nullptr); Error("failed to convert param #%d of type %s to broker data", i, type_name(got_type->Tag())); return rval; diff --git a/src/main.cc b/src/main.cc index acb0beb6e7..b44543173a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -84,44 +84,44 @@ int perftools_profile = 0; DNS_Mgr* dns_mgr; TimerMgr* timer_mgr; -ValManager* val_mgr = 0; -logging::Manager* log_mgr = 0; -threading::Manager* thread_mgr = 0; -input::Manager* input_mgr = 0; -plugin::Manager* plugin_mgr = 0; -analyzer::Manager* analyzer_mgr = 0; -file_analysis::Manager* file_mgr = 0; -zeekygen::Manager* zeekygen_mgr = 0; -iosource::Manager* iosource_mgr = 0; -bro_broker::Manager* broker_mgr = 0; -zeek::Supervisor* zeek::supervisor_mgr = 0; -trigger::Manager* trigger_mgr = 0; +ValManager* val_mgr = nullptr; +logging::Manager* log_mgr = nullptr; +threading::Manager* thread_mgr = nullptr; +input::Manager* input_mgr = nullptr; +plugin::Manager* plugin_mgr = nullptr; +analyzer::Manager* analyzer_mgr = nullptr; +file_analysis::Manager* file_mgr = nullptr; +zeekygen::Manager* zeekygen_mgr = nullptr; +iosource::Manager* iosource_mgr = nullptr; +bro_broker::Manager* broker_mgr = nullptr; +zeek::Supervisor* zeek::supervisor_mgr = nullptr; +trigger::Manager* trigger_mgr = nullptr; std::vector zeek_script_prefixes; Stmt* stmts; -EventHandlerPtr net_done = 0; -RuleMatcher* rule_matcher = 0; -EventRegistry* event_registry = 0; -ProfileLogger* profiling_logger = 0; -ProfileLogger* segment_logger = 0; -SampleLogger* sample_logger = 0; +EventHandlerPtr net_done = nullptr; +RuleMatcher* rule_matcher = nullptr; +EventRegistry* event_registry = nullptr; +ProfileLogger* profiling_logger = nullptr; +ProfileLogger* segment_logger = nullptr; +SampleLogger* sample_logger = nullptr; int signal_val = 0; extern char version[]; -const char* command_line_policy = 0; +const char* command_line_policy = nullptr; vector params; set requested_plugins; -const char* proc_status_file = 0; +const char* proc_status_file = nullptr; -OpaqueType* md5_type = 0; -OpaqueType* sha1_type = 0; -OpaqueType* sha256_type = 0; -OpaqueType* entropy_type = 0; -OpaqueType* cardinality_type = 0; -OpaqueType* topk_type = 0; -OpaqueType* bloomfilter_type = 0; -OpaqueType* x509_opaque_type = 0; -OpaqueType* ocsp_resp_opaque_type = 0; -OpaqueType* paraglob_type = 0; +OpaqueType* md5_type = nullptr; +OpaqueType* sha1_type = nullptr; +OpaqueType* sha256_type = nullptr; +OpaqueType* entropy_type = nullptr; +OpaqueType* cardinality_type = nullptr; +OpaqueType* topk_type = nullptr; +OpaqueType* bloomfilter_type = nullptr; +OpaqueType* x509_opaque_type = nullptr; +OpaqueType* ocsp_resp_opaque_type = nullptr; +OpaqueType* paraglob_type = nullptr; // Keep copy of command line int bro_argc; @@ -130,7 +130,7 @@ char** bro_argv; const char* zeek_version() { #ifdef DEBUG - static char* debug_version = 0; + static char* debug_version = nullptr; if ( ! debug_version ) { @@ -311,7 +311,7 @@ void terminate_bro() // free the global scope pop_scope(); - reporter = 0; + reporter = nullptr; } void zeek_terminate_loop(const char* reason) @@ -527,8 +527,8 @@ int main(int argc, char** argv) if ( options.random_seed_input_file ) seed_load_file = options.random_seed_input_file->data(); - init_random_seed((seed_load_file && *seed_load_file ? seed_load_file : 0), - options.random_seed_output_file ? options.random_seed_output_file->data() : 0); + init_random_seed((seed_load_file && *seed_load_file ? seed_load_file : nullptr), + options.random_seed_output_file ? options.random_seed_output_file->data() : nullptr); // DEBUG_MSG("HMAC key: %s\n", md5_digest_print(shared_hmac_md5_key)); init_hash_function(); @@ -748,7 +748,7 @@ int main(int argc, char** argv) if ( g_policy_debug ) // ### Add support for debug command file. - dbg_init_debugger(0); + dbg_init_debugger(nullptr); if ( ! options.pcap_file && ! options.interface ) { @@ -847,7 +847,7 @@ int main(int argc, char** argv) if ( stmts ) { stmt_flow_type flow; - Frame f(current_scope()->Length(), 0, 0); + Frame f(current_scope()->Length(), nullptr, nullptr); g_frame_stack.push_back(&f); try diff --git a/src/util.cc b/src/util.cc index e75e79882d..0b1128b296 100644 --- a/src/util.cc +++ b/src/util.cc @@ -277,7 +277,7 @@ std::string get_escaped_string(const char* str, size_t len, bool escape_all) char* copy_string(const char* s) { if ( ! s ) - return 0; + return nullptr; char* c = new char[strlen(s)+1]; strcpy(c, s); @@ -558,7 +558,7 @@ const char* strpbrk_n(size_t len, const char* s, const char* charset) if ( strchr(charset, *p) ) return p; - return 0; + return nullptr; } #ifndef HAVE_STRCASESTR @@ -819,7 +819,7 @@ const char* fmt_bytes(const char* data, int len) const char* vfmt(const char* format, va_list al) { - static char* buf = 0; + static char* buf = nullptr; static unsigned int buf_len = 1024; if ( ! buf ) @@ -1017,7 +1017,7 @@ void hmac_md5(size_t size, const unsigned char* bytes, unsigned char digest[16]) static bool read_random_seeds(const char* read_file, uint32_t* seed, uint32_t* buf, int bufsiz) { - FILE* f = 0; + FILE* f = nullptr; if ( ! (f = fopen(read_file, "r")) ) { @@ -1053,7 +1053,7 @@ static bool read_random_seeds(const char* read_file, uint32_t* seed, static bool write_random_seeds(const char* write_file, uint32_t seed, uint32_t* buf, int bufsiz) { - FILE* f = 0; + FILE* f = nullptr; if ( ! (f = fopen(write_file, "w+")) ) { @@ -1345,7 +1345,7 @@ bool is_package_loader(const string& path) FILE* open_file(const string& path, const string& mode) { if ( path.empty() ) - return 0; + return nullptr; FILE* rval = fopen(path.c_str(), mode.c_str()); @@ -1384,7 +1384,7 @@ FILE* open_package(string& path, const string& mode) string package_loader = "__load__" + script_extensions[0]; reporter->Error("Failed to open package '%s': missing '%s' file", arg_path.c_str(), package_loader.c_str()); - return 0; + return nullptr; } TEST_CASE("util path ops") @@ -1810,7 +1810,7 @@ FILE* rotate_file(const char* name, RecordVal* rotate_info) if ( ! newf ) { reporter->Error("rotate_file: can't open %s: %s", tmpname, strerror(errno)); - return 0; + return nullptr; } // Then move old file to ".." and make sure @@ -1822,7 +1822,7 @@ FILE* rotate_file(const char* name, RecordVal* rotate_info) fclose(newf); unlink(newname); unlink(tmpname); - return 0; + return nullptr; } // Close current file, and move the tmp to its place. diff --git a/src/util.h b/src/util.h index c212d5d8da..66d65ba622 100644 --- a/src/util.h +++ b/src/util.h @@ -139,7 +139,7 @@ inline std::string get_escaped_string(const std::string& str, bool escape_all) std::vector* tokenize_string(std::string_view input, std::string_view delim, - std::vector* rval = 0, int limit = 0); + std::vector* rval = nullptr, int limit = 0); std::vector tokenize_string(std::string_view input, const char delim) noexcept; @@ -167,7 +167,7 @@ extern char* strcasestr(const char* s, const char* find); #endif extern const char* strpbrk_n(size_t len, const char* s, const char* charset); template int atoi_n(int len, const char* s, const char** end, int base, T& result); -extern char* uitoa_n(uint64_t value, char* str, int n, int base, const char* prefix=0); +extern char* uitoa_n(uint64_t value, char* str, int n, int base, const char* prefix=nullptr); int strstr_n(const int big_len, const unsigned char* big, const int little_len, const unsigned char* little); extern int fputs(int len, const char* s, FILE* fp);