diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 43346f7d0f..2ea60a89cb 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -166,13 +166,13 @@ Manager::TableStream::~TableStream() if ( rtype ) // can be 0 for sets Unref(rtype); - if ( currDict != 0 ) + if ( currDict ) { currDict->Clear(); delete currDict; } - if ( lastDict != 0 ) + if ( lastDict ) { lastDict->Clear();; delete lastDict; @@ -211,7 +211,7 @@ ReaderBackend* Manager::CreateBackend(ReaderFrontend* frontend, EnumVal* tag) if ( ! c ) { reporter->Error("The reader that was requested was not found and could not be initialized."); - return 0; + return nullptr; } ReaderBackend* backend = (*c->Factory())(frontend); @@ -234,8 +234,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) string name = description->Lookup("name", true)->AsString()->CheckString(); - Stream *i = FindStream(name); - if ( i != 0 ) + if ( Stream *i = FindStream(name) ) { reporter->Error("Trying create already existing input stream %s", name.c_str()); @@ -551,7 +550,7 @@ bool Manager::CreateTableStream(RecordVal* fval) } auto event_val = fval->Lookup("ev", true); - Func* event = event_val ? event_val->AsFunc() : 0; + Func* event = event_val ? event_val->AsFunc() : nullptr; if ( event ) { @@ -672,13 +671,13 @@ bool Manager::CreateTableStream(RecordVal* fval) for ( unsigned int i = 0; i < fieldsV.size(); i++ ) fields[i] = fieldsV[i]; - stream->pred = pred ? pred->AsFunc() : 0; + stream->pred = pred ? pred->AsFunc() : nullptr; stream->num_idx_fields = idxfields; stream->num_val_fields = valfields; stream->tab = dst.release()->AsTableVal(); stream->rtype = val.release(); stream->itype = idx->Ref()->AsRecordType(); - stream->event = event ? event_registry->Lookup(event->Name()) : 0; + stream->event = event ? event_registry->Lookup(event->Name()) : nullptr; stream->error_event = error_event ? event_registry->Lookup(error_event->Name()) : nullptr; stream->currDict = new PDict; stream->currDict->SetDeleteFunc(input_hash_delete_func); @@ -769,7 +768,7 @@ bool Manager::CreateAnalysisStream(RecordVal* fval) // reader takes in a byte stream as the only field Field** fields = new Field*[1]; - fields[0] = new Field("bytestream", 0, TYPE_STRING, TYPE_VOID, false); + fields[0] = new Field("bytestream", nullptr, TYPE_STRING, TYPE_VOID, false); stream->reader->Init(1, fields); readers[stream->reader] = stream; @@ -833,7 +832,7 @@ bool Manager::IsCompatibleType(BroType* t, bool atomic_only) bool Manager::RemoveStream(Stream *i) { - if ( i == 0 ) + if ( i == nullptr ) return false; // not found if ( i->removed ) @@ -868,7 +867,7 @@ bool Manager::RemoveStreamContinuation(ReaderFrontend* reader) { Stream *i = FindStream(reader); - if ( i == 0 ) + if ( i == nullptr ) { reporter->Error("Stream not found in RemoveStreamContinuation"); return false; @@ -934,7 +933,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, else { string name = nameprepend + rec->FieldName(i); - const char* secondary = 0; + const char* secondary = nullptr; IntrusivePtr c; TypeTag ty = rec->FieldType(i)->Tag(); TypeTag st = TYPE_VOID; @@ -951,7 +950,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, { // we have an annotation for the second column - c = rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN)->AttrExpr()->Eval(0); + c = rec->FieldDecl(i)->FindAttr(ATTR_TYPE_COLUMN)->AttrExpr()->Eval(nullptr); assert(c); assert(c->Type()->Tag() == TYPE_STRING); @@ -973,7 +972,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, bool Manager::ForceUpdate(const string &name) { Stream *i = FindStream(name); - if ( i == 0 ) + if ( i == nullptr ) { reporter->Error("Stream %s not found", name.c_str()); return false; @@ -1057,7 +1056,7 @@ Val* Manager::ValueToIndexVal(const Stream* i, int num_fields, const RecordType void Manager::SendEntry(ReaderFrontend* reader, Value* *vals) { Stream *i = FindStream(reader); - if ( i == 0 ) + if ( i == nullptr ) { reporter->InternalWarning("Unknown reader %s in SendEntry", reader->Name()); @@ -1101,7 +1100,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) HashKey* idxhash = HashValues(stream->num_idx_fields, vals); - if ( idxhash == 0 ) + if ( idxhash == nullptr ) { Warning(i, "Could not hash line. Ignoring"); return stream->num_val_fields + stream->num_idx_fields; @@ -1110,21 +1109,20 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) hash_t valhash = 0; if ( stream->num_val_fields > 0 ) { - HashKey* valhashkey = HashValues(stream->num_val_fields, vals+stream->num_idx_fields); - if ( valhashkey == 0 ) - { - // empty line. index, but no values. - // hence we also have no hash value... - } - else + if ( HashKey* valhashkey = HashValues(stream->num_val_fields, vals+stream->num_idx_fields) ) { valhash = valhashkey->Hash(); delete(valhashkey); } + else + { + // empty line. index, but no values. + // hence we also have no hash value... + } } InputHash *h = stream->lastDict->Lookup(idxhash); - if ( h != 0 ) + if ( h ) { // seen before if ( stream->num_val_fields == 0 || h->valhash == valhash ) @@ -1148,14 +1146,14 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) } Val* valval; - RecordVal* predidx = 0; + RecordVal* predidx = nullptr; int position = stream->num_idx_fields; bool convert_error = false; // this will be set to true by ValueTo* on Error if ( stream->num_val_fields == 0 ) - valval = 0; + valval = nullptr; else if ( stream->num_val_fields == 1 && !stream->want_record ) valval = ValueToVal(i, vals[position], stream->rtype->FieldType(0), convert_error); @@ -1213,10 +1211,10 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) // now we don't need h anymore - if we are here, the entry is updated and a new h is created. delete h; - h = 0; + h = nullptr; Val* idxval; - if ( predidx != 0 ) + if ( predidx != nullptr ) { idxval = RecordValToIndexVal(predidx); // I think there is an unref missing here. But if I insert is, it crashes :) @@ -1256,7 +1254,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) stream->tab->Assign(idxval, k, valval); Unref(idxval); // asssign does not consume idxval. - if ( predidx != 0 ) + if ( predidx != nullptr ) Unref(predidx); auto prev = stream->currDict->Insert(idxhash, ih); @@ -1279,7 +1277,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) { // in case of update send back the old value. assert ( stream->num_val_fields > 0 ); ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); - assert ( oldval != 0 ); + assert ( oldval != nullptr ); SendEvent(stream->event, 4, stream->description->Ref(), ev, predidx, oldval.release()); } else @@ -1302,7 +1300,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) { Stream *i = FindStream(reader); - if ( i == 0 ) + if ( i == nullptr ) { reporter->InternalWarning("Unknown reader %s in EndCurrentSend", reader->Name()); @@ -1336,8 +1334,8 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) { IntrusivePtr val; - Val* predidx = 0; - EnumVal* ev = 0; + Val* predidx = nullptr; + EnumVal* ev = nullptr; int startpos = 0; if ( stream->pred || stream->event ) @@ -1345,7 +1343,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) auto idx = stream->tab->RecoverIndex(ih->idxkey); assert(idx != nullptr); val = stream->tab->Lookup(idx.get()); - assert(val != 0); + assert(val != nullptr); predidx = ListValToRecordVal(idx.get(), stream->itype, &startpos); ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); } @@ -1409,7 +1407,7 @@ void Manager::SendEndOfData(ReaderFrontend* reader) { Stream *i = FindStream(reader); - if ( i == 0 ) + if ( i == nullptr ) { reporter->InternalWarning("Unknown reader %s in SendEndOfData", reader->Name()); @@ -1436,7 +1434,7 @@ void Manager::SendEndOfData(const Stream *i) void Manager::Put(ReaderFrontend* reader, Value* *vals) { Stream *i = FindStream(reader); - if ( i == 0 ) + if ( i == nullptr ) { reporter->InternalWarning("Unknown reader %s in Put", reader->Name()); return; @@ -1500,7 +1498,7 @@ int Manager::SendEventStreamEvent(Stream* i, EnumVal* type, const Value* const * { for ( int j = 0; j < stream->fields->NumFields(); j++) { - Val* val = 0; + Val* val = nullptr; if ( stream->fields->FieldType(j)->Tag() == TYPE_RECORD ) val = ValueToRecordVal(i, vals, @@ -1544,7 +1542,7 @@ int Manager::PutTable(Stream* i, const Value* const *vals) int position = stream->num_idx_fields; if ( stream->num_val_fields == 0 ) - valval = 0; + valval = nullptr; else if ( stream->num_val_fields == 1 && stream->want_record == 0 ) valval = ValueToVal(i, vals[position], stream->rtype->FieldType(0), convert_error); @@ -1571,7 +1569,7 @@ int Manager::PutTable(Stream* i, const Value* const *vals) oldval = stream->tab->Lookup(idxval, false); } - if ( oldval != 0 ) + if ( oldval != nullptr ) { // it is an update updated = true; @@ -1633,7 +1631,7 @@ int Manager::PutTable(Stream* i, const Value* const *vals) // in case of update send back the old value. assert ( stream->num_val_fields > 0 ); ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_CHANGED).release(); - assert ( oldval != 0 ); + assert ( oldval != nullptr ); SendEvent(stream->event, 4, stream->description->Ref(), ev, predidx, oldval.release()); } @@ -1665,7 +1663,7 @@ int Manager::PutTable(Stream* i, const Value* const *vals) void Manager::Clear(ReaderFrontend* reader) { Stream *i = FindStream(reader); - if ( i == 0 ) + if ( i == nullptr ) { reporter->InternalWarning("Unknown reader %s in Clear", reader->Name()); @@ -1687,7 +1685,7 @@ void Manager::Clear(ReaderFrontend* reader) bool Manager::Delete(ReaderFrontend* reader, Value* *vals) { Stream *i = FindStream(reader); - if ( i == 0 ) + if ( i == nullptr ) { reporter->InternalWarning("Unknown reader %s in Delete", reader->Name()); return false; @@ -1701,7 +1699,7 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals) TableStream* stream = (TableStream*) i; bool convert_error = false; Val* idxval = ValueToIndexVal(i, stream->num_idx_fields, stream->itype, vals, convert_error); - assert(idxval != 0); + assert(idxval != nullptr); readVals = stream->num_idx_fields + stream->num_val_fields; bool streamresult = true; @@ -1742,7 +1740,7 @@ bool Manager::Delete(ReaderFrontend* reader, Value* *vals) if ( streamresult && stream->event ) { Ref(idxval); - assert(val != 0); + assert(val != nullptr); EnumVal* ev = BifType::Enum::Input::Event->GetVal(BifEnum::Input::EVENT_REMOVED).release(); SendEvent(stream->event, 4, stream->description->Ref(), ev, idxval, IntrusivePtr{val}.release()); } @@ -1806,7 +1804,7 @@ bool Manager::CallPred(Func* pred_func, const int numvals, ...) const bool Manager::SendEvent(ReaderFrontend* reader, const string& name, const int num_vals, Value* *vals) const { Stream *i = FindStream(reader); - if ( i == 0 ) + if ( i == nullptr ) { reporter->InternalWarning("Unknown reader %s in SendEvent for event %s", reader->Name(), name.c_str()); delete_value_ptr_array(vals, num_vals); @@ -1814,7 +1812,7 @@ bool Manager::SendEvent(ReaderFrontend* reader, const string& name, const int nu } EventHandler* handler = event_registry->Lookup(name); - if ( handler == 0 ) + if ( handler == nullptr ) { Warning(i, "Event %s not found", name.c_str()); delete_value_ptr_array(vals, num_vals); @@ -1904,18 +1902,18 @@ void Manager::SendEvent(EventHandlerPtr ev, list events) const // I / we could think about moving this functionality to val.cc RecordVal* Manager::ListValToRecordVal(ListVal* list, RecordType *request_type, int* position) const { - assert(position != 0 ); // we need the pointer to point to data; + assert(position != nullptr); // we need the pointer to point to data; RecordVal* rec = new RecordVal(request_type->AsRecordType()); - assert(list != 0); + assert(list != nullptr); int maxpos = list->Length(); for ( int i = 0; i < request_type->NumFields(); i++ ) { assert ( (*position) <= maxpos ); - Val* fieldVal = 0; + Val* fieldVal = nullptr; if ( request_type->FieldType(i)->Tag() == TYPE_RECORD ) fieldVal = ListValToRecordVal(list, request_type->FieldType(i)->AsRecordType(), position); else @@ -1934,12 +1932,12 @@ RecordVal* Manager::ListValToRecordVal(ListVal* list, RecordType *request_type, RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const *vals, RecordType *request_type, int* position, bool& have_error) const { - assert(position != 0); // we need the pointer to point to data. + assert(position != nullptr); // we need the pointer to point to data. RecordVal* rec = new RecordVal(request_type->AsRecordType()); for ( int i = 0; i < request_type->NumFields(); i++ ) { - Val* fieldVal = 0; + Val* fieldVal = nullptr; if ( request_type->FieldType(i)->Tag() == TYPE_RECORD ) fieldVal = ValueToRecordVal(stream, vals, request_type->FieldType(i)->AsRecordType(), position, have_error); else if ( request_type->FieldType(i)->Tag() == TYPE_FILE || @@ -2215,7 +2213,7 @@ HashKey* Manager::HashValues(const int num_elements, const Value* const *vals) c assert ( length >= num_elements ); if ( length == num_elements ) - return NULL; + return nullptr; int position = 0; char *data = new char[length]; @@ -2285,7 +2283,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ case TYPE_ADDR: { - IPAddr* addr = 0; + IPAddr* addr = nullptr; switch ( val->val.addr_val.family ) { case IPv4: addr = new IPAddr(val->val.addr_val.in.in4); @@ -2344,7 +2342,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ { Val* assignval = ValueToVal(i, val->val.set_val.vals[j], type, have_error); - t->Assign(assignval, 0); + t->Assign(assignval, nullptr); Unref(assignval); // index is not consumed by assign. } @@ -2395,7 +2393,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ } assert(false); - return NULL; + return nullptr; } Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) const @@ -2433,7 +2431,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co case TYPE_ADDR: { - IPAddr* addr = 0; + IPAddr* addr = nullptr; switch ( val->val.addr_val.family ) { case IPv4: addr = new IPAddr(val->val.addr_val.in.in4); @@ -2526,7 +2524,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co { Val* assignval = ValueToVal(i, val->val.set_val.vals[j], have_error); - t->Assign(assignval, 0); + t->Assign(assignval, nullptr); Unref(assignval); // index is not consumed by assign. } @@ -2593,7 +2591,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co } assert(false); - return NULL; + return nullptr; } Manager::Stream* Manager::FindStream(const string &name) const @@ -2604,7 +2602,7 @@ Manager::Stream* Manager::FindStream(const string &name) const return (*s).second; } - return 0; + return nullptr; } Manager::Stream* Manager::FindStream(ReaderFrontend* reader) const @@ -2613,7 +2611,7 @@ Manager::Stream* Manager::FindStream(ReaderFrontend* reader) const if ( s != readers.end() ) return s->second; - return 0; + return nullptr; } // Function is called on Bro shutdown. diff --git a/src/input/ReaderBackend.cc b/src/input/ReaderBackend.cc index 656743abb5..90050a6438 100644 --- a/src/input/ReaderBackend.cc +++ b/src/input/ReaderBackend.cc @@ -204,7 +204,7 @@ ReaderBackend::ReaderBackend(ReaderFrontend* arg_frontend) : MsgThread() frontend = arg_frontend; info = new ReaderInfo(frontend->Info()); num_fields = 0; - fields = 0; + fields = nullptr; SetName(frontend->Name()); } @@ -282,13 +282,13 @@ bool ReaderBackend::OnFinish(double network_time) disabled = true; // frontend disables itself when it gets the Close-message. SendOut(new ReaderClosedMessage(frontend)); - if ( fields != 0 ) + if ( fields ) { for ( unsigned int i = 0; i < num_fields; i++ ) delete(fields[i]); delete [] (fields); - fields = 0; + fields = nullptr; } return true; diff --git a/src/input/ReaderBackend.h b/src/input/ReaderBackend.h index 3219359f71..d158d0972c 100644 --- a/src/input/ReaderBackend.h +++ b/src/input/ReaderBackend.h @@ -104,15 +104,15 @@ public: ReaderInfo() { - source = 0; - name = 0; + source = nullptr; + name = nullptr; mode = MODE_NONE; } ReaderInfo(const ReaderInfo& other) { - source = other.source ? copy_string(other.source) : 0; - name = other.name ? copy_string(other.name) : 0; + source = other.source ? copy_string(other.source) : nullptr; + name = other.name ? copy_string(other.name) : nullptr; mode = other.mode; for ( config_map::const_iterator i = other.config.begin(); i != other.config.end(); i++ ) diff --git a/src/input/ReaderFrontend.cc b/src/input/ReaderFrontend.cc index 898d4b30da..7fce36ee71 100644 --- a/src/input/ReaderFrontend.cc +++ b/src/input/ReaderFrontend.cc @@ -52,7 +52,7 @@ void ReaderFrontend::Stop() if ( backend ) { backend->SignalStop(); - backend = 0; // Thread manager will clean it up once it finishes. + backend = nullptr; // Thread manager will clean it up once it finishes. } } diff --git a/src/input/readers/ascii/Ascii.cc b/src/input/readers/ascii/Ascii.cc index 2bf2cff996..d04fbe713d 100644 --- a/src/input/readers/ascii/Ascii.cc +++ b/src/input/readers/ascii/Ascii.cc @@ -396,7 +396,7 @@ bool Ascii::DoUpdate() Value* val = formatter->ParseValue(stringfields[(*fit).position], (*fit).name, (*fit).type, (*fit).subtype); - if ( val == 0 ) + if ( ! val ) { Warning(Fmt("Could not convert line '%s' of %s to Val. Ignoring line.", line.c_str(), fname.c_str())); error = true; diff --git a/src/input/readers/benchmark/Benchmark.cc b/src/input/readers/benchmark/Benchmark.cc index 49e989909c..32d57787c1 100644 --- a/src/input/readers/benchmark/Benchmark.cc +++ b/src/input/readers/benchmark/Benchmark.cc @@ -210,11 +210,11 @@ threading::Value* Benchmark::EntryToVal(TypeTag type, TypeTag subtype) for ( unsigned int pos = 0; pos < length; pos++ ) { Value* newval = EntryToVal(subtype, TYPE_ENUM); - if ( newval == 0 ) + if ( newval == nullptr ) { Error("Error while reading set"); delete val; - return 0; + return nullptr; } lvals[pos] = newval; } @@ -226,7 +226,7 @@ threading::Value* Benchmark::EntryToVal(TypeTag type, TypeTag subtype) default: Error(Fmt("unsupported field format %d", type)); delete val; - return 0; + return nullptr; } return val; @@ -265,7 +265,7 @@ bool Benchmark::DoHeartbeat(double network_time, double current_time) Update(); // call update and not DoUpdate, because update actually checks disabled. - SendEvent("HeartbeatDone", 0, 0); + SendEvent("HeartbeatDone", 0, nullptr); break; default: diff --git a/src/input/readers/binary/Binary.cc b/src/input/readers/binary/Binary.cc index 87c38d16aa..22a7121e13 100644 --- a/src/input/readers/binary/Binary.cc +++ b/src/input/readers/binary/Binary.cc @@ -14,7 +14,7 @@ using threading::Field; streamsize Binary::chunk_size = 0; Binary::Binary(ReaderFrontend *frontend) - : ReaderBackend(frontend), in(0), mtime(0), ino(0), firstrun(true) + : ReaderBackend(frontend), in(nullptr), mtime(0), ino(0), firstrun(true) { if ( ! chunk_size ) { @@ -64,7 +64,7 @@ bool Binary::CloseInput() in->close(); delete in; - in = 0; + in = nullptr; #ifdef DEBUG Debug(DBG_INPUT, "Binary reader finished close"); @@ -76,7 +76,7 @@ bool Binary::CloseInput() bool Binary::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fields) { - in = 0; + in = nullptr; mtime = 0; ino = 0; firstrun = true; @@ -158,7 +158,7 @@ streamsize Binary::GetChunk(char** chunk) if ( ! bytes_read ) { delete [] *chunk; - *chunk = 0; + *chunk = nullptr; return 0; } @@ -231,7 +231,7 @@ bool Binary::DoUpdate() } } - char* chunk = 0; + char* chunk = nullptr; streamsize size = 0; while ( (size = GetChunk(&chunk)) ) { diff --git a/src/input/readers/sqlite/SQLite.cc b/src/input/readers/sqlite/SQLite.cc index 821e6cdd9a..e831db8c62 100644 --- a/src/input/readers/sqlite/SQLite.cc +++ b/src/input/readers/sqlite/SQLite.cc @@ -156,7 +156,7 @@ Value* SQLite::EntryToVal(sqlite3_stmt *st, const threading::Field *field, int p { Error("Invalid data type for boolean - expected Integer"); delete val; - return 0; + return nullptr; } int res = sqlite3_column_int(st, pos); @@ -167,7 +167,7 @@ Value* SQLite::EntryToVal(sqlite3_stmt *st, const threading::Field *field, int p { Error(Fmt("Invalid value for boolean: %d", res)); delete val; - return 0; + return nullptr; } break; } @@ -240,7 +240,7 @@ Value* SQLite::EntryToVal(sqlite3_stmt *st, const threading::Field *field, int p default: Error(Fmt("unsupported field format %d", field->type)); delete val; - return 0; + return nullptr; } return val; @@ -279,7 +279,7 @@ bool SQLite::DoUpdate() mapping[j] = i; } - if ( fields[j]->secondary_name != 0 && strcmp(fields[j]->secondary_name, name) == 0 ) + if ( fields[j]->secondary_name != nullptr && strcmp(fields[j]->secondary_name, name) == 0 ) { assert(fields[j]->type == TYPE_PORT); if ( submapping[j] != -1 ) @@ -314,7 +314,7 @@ bool SQLite::DoUpdate() for ( unsigned int j = 0; j < num_fields; ++j) { ofields[j] = EntryToVal(st, fields[j], mapping[j], submapping[j]); - if ( ofields[j] == 0 ) + if ( ! ofields[j] ) { for ( unsigned int k = 0; k < j; ++k ) delete ofields[k]; diff --git a/src/iosource/BPF_Program.cc b/src/iosource/BPF_Program.cc index 8a97a6fc25..165b2fa2b2 100644 --- a/src/iosource/BPF_Program.cc +++ b/src/iosource/BPF_Program.cc @@ -143,7 +143,7 @@ bool BPF_Program::Compile(int snaplen, int linktype, const char* filter, bpf_program* BPF_Program::GetProgram() { - return m_compiled ? &m_program : 0; + return m_compiled ? &m_program : nullptr; } void BPF_Program::FreeCode() diff --git a/src/iosource/BPF_Program.h b/src/iosource/BPF_Program.h index de06e9d13a..0ff37bfd1f 100644 --- a/src/iosource/BPF_Program.h +++ b/src/iosource/BPF_Program.h @@ -22,14 +22,14 @@ public: // Parameters are like in pcap_compile(). Returns true // for successful compilation, false otherwise. bool Compile(pcap_t* pcap, const char* filter, uint32_t netmask, - char* errbuf = 0, unsigned int errbuf_len = 0, + char* errbuf = nullptr, unsigned int errbuf_len = 0, bool optimize = true); // Creates a BPF program when no pcap handle is around, // similarly to pcap_compile_nopcap(). Parameters are // similar. Returns true on success. bool Compile(int snaplen, int linktype, const char* filter, - uint32_t netmask, char* errbuf = 0, unsigned int errbuf_len = 0, + uint32_t netmask, char* errbuf = nullptr, unsigned int errbuf_len = 0, bool optimize = true); // Returns true if this program currently contains compiled diff --git a/src/iosource/Manager.cc b/src/iosource/Manager.cc index 6bfa1ad420..217bdf0f8a 100644 --- a/src/iosource/Manager.cc +++ b/src/iosource/Manager.cc @@ -330,7 +330,7 @@ PktSrc* Manager::OpenPktSrc(const std::string& path, bool is_live) // Find the component providing packet sources of the requested prefix. - PktSrcComponent* component = 0; + PktSrcComponent* component = nullptr; std::list all_components = plugin_mgr->Components(); for ( const auto& c : all_components ) @@ -372,7 +372,7 @@ PktDumper* Manager::OpenPktDumper(const string& path, bool append) // Find the component providing packet dumpers of the requested prefix. - PktDumperComponent* component = 0; + PktDumperComponent* component = nullptr; std::list all_components = plugin_mgr->Components(); for ( const auto& c : all_components ) diff --git a/src/iosource/Packet.h b/src/iosource/Packet.h index 4913514678..2da4836b7b 100644 --- a/src/iosource/Packet.h +++ b/src/iosource/Packet.h @@ -59,7 +59,7 @@ public: Packet(int link_type, pkt_timeval *ts, uint32_t caplen, uint32_t len, const u_char *data, bool copy = false, std::string tag = std::string("")) - : data(0), l2_src(0), l2_dst(0) + : data(nullptr), l2_src(nullptr), l2_dst(nullptr) { Init(link_type, ts, caplen, len, data, copy, tag); } @@ -67,10 +67,10 @@ public: /** * Default constructor. For internal use only. */ - Packet() : data(0), l2_src(0), l2_dst(0) + Packet() : data(nullptr), l2_src(nullptr), l2_dst(nullptr) { pkt_timeval ts = {0, 0}; - Init(0, &ts, 0, 0, 0); + Init(0, &ts, 0, 0, nullptr); } /** diff --git a/src/iosource/PktDumper.cc b/src/iosource/PktDumper.cc index 9a49ccb6fb..f0d911b9b4 100644 --- a/src/iosource/PktDumper.cc +++ b/src/iosource/PktDumper.cc @@ -45,12 +45,12 @@ double PktDumper::OpenTime() const bool PktDumper::IsError() const { - return errmsg.size(); + return ! errmsg.empty(); } const char* PktDumper::ErrorMsg() const { - return errmsg.size() ? errmsg.c_str() : 0; + return errmsg.size() ? errmsg.c_str() : nullptr; } int PktDumper::HdrSize() const diff --git a/src/iosource/PktSrc.cc b/src/iosource/PktSrc.cc index 19bf1f3f52..53c2a747aa 100644 --- a/src/iosource/PktSrc.cc +++ b/src/iosource/PktSrc.cc @@ -51,7 +51,7 @@ const std::string& PktSrc::Path() const const char* PktSrc::ErrorMsg() const { - return errbuf.size() ? errbuf.c_str() : 0; + return errbuf.size() ? errbuf.c_str() : nullptr; } int PktSrc::LinkType() const @@ -66,7 +66,7 @@ uint32_t PktSrc::Netmask() const bool PktSrc::IsError() const { - return ErrorMsg(); + return ! errbuf.empty(); } bool PktSrc::IsLive() const @@ -153,7 +153,7 @@ void PktSrc::Info(const std::string& msg) void PktSrc::Weird(const std::string& msg, const Packet* p) { - sessions->Weird(msg.c_str(), p, 0); + sessions->Weird(msg.c_str(), p, nullptr); } void PktSrc::InternalError(const std::string& msg) @@ -299,9 +299,9 @@ bool PktSrc::PrecompileBPFFilter(int index, const std::string& filter) BPF_Program* PktSrc::GetBPFFilter(int index) { if ( index < 0 ) - return 0; + return nullptr; - return (static_cast(filters.size()) > index ? filters[index] : 0); + return (static_cast(filters.size()) > index ? filters[index] : nullptr); } bool PktSrc::ApplyBPFFilter(int index, const struct pcap_pkthdr *hdr, const u_char *pkt) diff --git a/src/iosource/pcap/Dumper.cc b/src/iosource/pcap/Dumper.cc index e6e400477e..5bbf12dfa6 100644 --- a/src/iosource/pcap/Dumper.cc +++ b/src/iosource/pcap/Dumper.cc @@ -15,8 +15,8 @@ PcapDumper::PcapDumper(const std::string& path, bool arg_append) { append = arg_append; props.path = path; - dumper = 0; - pd = 0; + dumper = nullptr; + pd = nullptr; } PcapDumper::~PcapDumper() @@ -93,8 +93,8 @@ void PcapDumper::Close() pcap_dump_close(dumper); pcap_close(pd); - dumper = 0; - pd = 0; + dumper = nullptr; + pd = nullptr; Closed(); } diff --git a/src/iosource/pcap/Source.h b/src/iosource/pcap/Source.h index f32071cb99..24271b6613 100644 --- a/src/iosource/pcap/Source.h +++ b/src/iosource/pcap/Source.h @@ -33,7 +33,7 @@ protected: private: void OpenLive(); void OpenOffline(); - void PcapError(const char* where = 0); + void PcapError(const char* where = nullptr); Properties props; Stats stats; diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index d1af7e674c..b5f399f98f 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -147,7 +147,7 @@ WriterBackend* Manager::CreateBackend(WriterFrontend* frontend, EnumVal* tag) if ( ! c ) { reporter->Error("unknown writer type requested"); - return 0; + return nullptr; } WriterBackend* backend = (*c->Factory())(frontend); @@ -161,7 +161,7 @@ Manager::Stream* Manager::FindStream(EnumVal* id) unsigned int idx = id->AsEnum(); if ( idx >= streams.size() || ! streams[idx] ) - return 0; + return nullptr; return streams[idx]; } @@ -182,7 +182,7 @@ Manager::WriterInfo* Manager::FindWriter(WriterFrontend* writer) } } - return 0; + return nullptr; } bool Manager::CompareFields(const Filter* filter, const WriterFrontend* writer) @@ -264,7 +264,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) } auto event_val = sval->Lookup("ev"); - Func* event = event_val ? event_val->AsFunc() : 0; + Func* event = event_val ? event_val->AsFunc() : nullptr; if ( event ) { @@ -298,7 +298,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) unsigned int idx = id->AsEnum(); while ( idx >= streams.size() ) - streams.push_back(0); + streams.push_back(nullptr); if ( streams[idx] ) // We already know this one, delete the previous definition. @@ -309,7 +309,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) streams[idx]->id = id->Ref()->AsEnumVal(); streams[idx]->enabled = true; streams[idx]->name = id->Type()->AsEnumType()->Lookup(idx); - streams[idx]->event = event ? event_registry->Lookup(event->Name()) : 0; + streams[idx]->event = event ? event_registry->Lookup(event->Name()) : nullptr; streams[idx]->columns = columns->Ref()->AsRecordType(); streams[idx]->enable_remote = internal_val("Log::enable_remote_logging")->AsBool(); @@ -347,7 +347,7 @@ bool Manager::RemoveStream(EnumVal* id) stream->writers.clear(); string sname(stream->name); delete stream; - streams[idx] = 0; + streams[idx] = nullptr; DBG_LOG(DBG_LOGGING, "Removed logging stream '%s'", sname.c_str()); return true; @@ -523,7 +523,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, bool optional = rtype->FieldDecl(i)->FindAttr(ATTR_OPTIONAL); - filter->fields[filter->num_fields - 1] = new threading::Field(new_path.c_str(), 0, t->Tag(), st, optional); + filter->fields[filter->num_fields - 1] = new threading::Field(new_path.c_str(), nullptr, t->Tag(), st, optional); } return true; @@ -565,18 +565,18 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) filter->fval = fval->Ref(); filter->name = name->AsString()->CheckString(); filter->id = id->Ref()->AsEnumVal(); - filter->pred = pred ? pred->AsFunc() : 0; - filter->path_func = path_func ? path_func->AsFunc() : 0; + filter->pred = pred ? pred->AsFunc() : nullptr; + filter->path_func = path_func ? path_func->AsFunc() : nullptr; filter->writer = writer->Ref()->AsEnumVal(); filter->local = log_local->AsBool(); filter->remote = log_remote->AsBool(); filter->interval = interv->AsInterval(); - filter->postprocessor = postprocessor ? postprocessor->AsFunc() : 0; + filter->postprocessor = postprocessor ? postprocessor->AsFunc() : nullptr; filter->config = config->Ref()->AsTableVal(); filter->field_name_map = field_name_map->Ref()->AsTableVal(); filter->scope_sep = scope_sep->AsString()->CheckString(); filter->ext_prefix = ext_prefix->AsString()->CheckString(); - filter->ext_func = ext_func ? ext_func->AsFunc() : 0; + filter->ext_func = ext_func ? ext_func->AsFunc() : nullptr; // Build the list of fields that the filter wants included, including // potentially rolling out fields. @@ -604,7 +604,7 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) } filter->num_fields = 0; - filter->fields = 0; + filter->fields = nullptr; if ( ! TraverseRecord(stream, filter, stream->columns, include ? include->AsTableVal() : nullptr, exclude ? exclude->AsTableVal() : nullptr, @@ -627,7 +627,7 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) { // If no path is given, it's derived based upon the value returned by // the first call to the filter's path_func (during first write). - filter->path_val = 0; + filter->path_val = nullptr; } // Remove any filter with the same name we might already have. @@ -811,8 +811,8 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) path = filter->path = filter->path_val->AsString()->CheckString(); } - WriterBackend::WriterInfo* info = 0; - WriterFrontend* writer = 0; + WriterBackend::WriterInfo* info = nullptr; + WriterFrontend* writer = nullptr; if ( w != stream->writers.end() ) { @@ -1125,7 +1125,7 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken int num_fields, const threading::Field* const* fields, bool local, bool remote, bool from_remote, const string& instantiating_filter) { - WriterFrontend* result = 0; + WriterFrontend* result = nullptr; Stream* stream = FindStream(id); @@ -1133,7 +1133,7 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken { // Don't know this stream. delete_info_and_fields(info, num_fields, fields); - return 0; + return nullptr; } Stream::WriterMap::iterator w = @@ -1149,11 +1149,11 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken WriterInfo* winfo = new WriterInfo; winfo->type = writer->Ref()->AsEnumVal(); - winfo->writer = 0; + winfo->writer = nullptr; winfo->open_time = network_time; - winfo->rotation_timer = 0; + winfo->rotation_timer = nullptr; winfo->interval = 0; - winfo->postprocessor = 0; + winfo->postprocessor = nullptr; winfo->info = info; winfo->from_remote = from_remote; winfo->hook_initialized = false; @@ -1194,7 +1194,7 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken // Still need to set the WriterInfo's rotation parameters, which we // computed above. const char* base_time = log_rotate_base_time ? - log_rotate_base_time->AsString()->CheckString() : 0; + log_rotate_base_time->AsString()->CheckString() : nullptr; winfo->info->rotation_interval = winfo->interval; winfo->info->rotation_base = parse_rotate_base_time(base_time); @@ -1411,12 +1411,12 @@ protected: RotationTimer::~RotationTimer() { if ( winfo->rotation_timer == this ) - winfo->rotation_timer = 0; + winfo->rotation_timer = nullptr; } void RotationTimer::Dispatch(double t, bool is_expire) { - winfo->rotation_timer = 0; + winfo->rotation_timer = nullptr; if ( rotate ) log_mgr->Rotate(winfo); @@ -1436,7 +1436,7 @@ void Manager::InstallRotationTimer(WriterInfo* winfo) if ( winfo->rotation_timer ) { timer_mgr->Cancel(winfo->rotation_timer); - winfo->rotation_timer = 0; + winfo->rotation_timer = nullptr; } double rotation_interval = winfo->interval; @@ -1454,7 +1454,7 @@ void Manager::InstallRotationTimer(WriterInfo* winfo) winfo->open_time = network_time; const char* base_time = log_rotate_base_time ? - log_rotate_base_time->AsString()->CheckString() : 0; + log_rotate_base_time->AsString()->CheckString() : nullptr; double base = parse_rotate_base_time(base_time); double delta_t = diff --git a/src/logging/Manager.h b/src/logging/Manager.h index 4d062c6a07..55dc5b68c0 100644 --- a/src/logging/Manager.h +++ b/src/logging/Manager.h @@ -261,7 +261,7 @@ private: threading::Value** RecordToFilterVals(Stream* stream, Filter* filter, RecordVal* columns); - threading::Value* ValToLogVal(Val* val, BroType* ty = 0); + threading::Value* ValToLogVal(Val* val, BroType* ty = nullptr); Stream* FindStream(EnumVal* id); void RemoveDisabledWriters(Stream* stream); void InstallRotationTimer(WriterInfo* winfo); diff --git a/src/logging/WriterBackend.cc b/src/logging/WriterBackend.cc index 4512234734..b3bbe8b13e 100644 --- a/src/logging/WriterBackend.cc +++ b/src/logging/WriterBackend.cc @@ -121,7 +121,7 @@ bool WriterBackend::WriterInfo::FromBroker(broker::data d) WriterBackend::WriterBackend(WriterFrontend* arg_frontend) : MsgThread() { num_fields = 0; - fields = 0; + fields = nullptr; buffering = true; frontend = arg_frontend; info = new WriterInfo(frontend->Info()); @@ -168,7 +168,7 @@ bool WriterBackend::FinishedRotation(const char* new_name, const char* old_name, bool WriterBackend::FinishedRotation() { --rotation_counter; - SendOut(new RotationFinishedMessage(frontend, 0, 0, 0, 0, false, false)); + SendOut(new RotationFinishedMessage(frontend, nullptr, nullptr, 0, 0, false, false)); return true; } diff --git a/src/logging/WriterBackend.h b/src/logging/WriterBackend.h index bb0941322d..805b4f8b9a 100644 --- a/src/logging/WriterBackend.h +++ b/src/logging/WriterBackend.h @@ -82,14 +82,14 @@ public: */ config_map config; - WriterInfo() : path(0), rotation_interval(0.0), rotation_base(0.0), + WriterInfo() : path(nullptr), rotation_interval(0.0), rotation_base(0.0), network_time(0.0) { } WriterInfo(const WriterInfo& other) { - path = other.path ? copy_string(other.path) : 0; + path = other.path ? copy_string(other.path) : nullptr; rotation_interval = other.rotation_interval; rotation_base = other.rotation_base; network_time = other.network_time; diff --git a/src/logging/WriterFrontend.cc b/src/logging/WriterFrontend.cc index f8ce418482..c8953b817e 100644 --- a/src/logging/WriterFrontend.cc +++ b/src/logging/WriterFrontend.cc @@ -109,12 +109,12 @@ WriterFrontend::WriterFrontend(const WriterBackend::WriterInfo& arg_info, EnumVa buf = true; local = arg_local; remote = arg_remote; - write_buffer = 0; + write_buffer = nullptr; write_buffer_pos = 0; info = new WriterBackend::WriterInfo(arg_info); num_fields = 0; - fields = 0; + fields = nullptr; const char* w = arg_writer->Type()->AsEnumType()->Lookup(arg_writer->InternalInt()); name = copy_string(fmt("%s/%s", arg_info.path, w)); @@ -128,7 +128,7 @@ WriterFrontend::WriterFrontend(const WriterBackend::WriterInfo& arg_info, EnumVa } else - backend = 0; + backend = nullptr; } WriterFrontend::~WriterFrontend() @@ -152,7 +152,7 @@ void WriterFrontend::Stop() if ( backend ) { backend->SignalStop(); - backend = 0; // Thread manager will clean it up once it finishes. + backend = nullptr; // Thread manager will clean it up once it finishes. } } @@ -245,7 +245,7 @@ void WriterFrontend::FlushWriteBuffer() backend->SendIn(new WriteMessage(backend, num_fields, write_buffer_pos, write_buffer)); // Clear buffer (no delete, we pass ownership to child thread.) - write_buffer = 0; + write_buffer = nullptr; write_buffer_pos = 0; } @@ -286,7 +286,7 @@ void WriterFrontend::Rotate(const char* rotated_path, double open, double close, backend->SendIn(new RotateMessage(backend, this, rotated_path, open, close, terminating)); else // Still signal log manager that we're done. - log_mgr->FinishedRotation(this, 0, 0, 0, 0, false, terminating); + log_mgr->FinishedRotation(this, nullptr, nullptr, 0, 0, false, terminating); } void WriterFrontend::DeleteVals(int num_fields, Value** vals) diff --git a/src/logging/writers/ascii/Ascii.cc b/src/logging/writers/ascii/Ascii.cc index f598cdc216..71c47042ba 100644 --- a/src/logging/writers/ascii/Ascii.cc +++ b/src/logging/writers/ascii/Ascii.cc @@ -24,7 +24,7 @@ Ascii::Ascii(WriterFrontend* frontend) : WriterBackend(frontend) tsv = false; use_json = false; enable_utf_8 = false; - formatter = 0; + formatter = nullptr; gzip_level = 0; gzfile = nullptr; @@ -179,7 +179,7 @@ bool Ascii::InitFilterOptions() bool Ascii::InitFormatter() { delete formatter; - formatter = 0; + formatter = nullptr; if ( use_json ) { diff --git a/src/threading/BasicThread.cc b/src/threading/BasicThread.cc index 3374380748..c447051bab 100644 --- a/src/threading/BasicThread.cc +++ b/src/threading/BasicThread.cc @@ -22,7 +22,7 @@ BasicThread::BasicThread() buf_len = STD_FMT_BUF_LEN; buf = (char*) safe_malloc(buf_len); - strerr_buffer = 0; + strerr_buffer = nullptr; name = copy_string(fmt("thread-%" PRIu64, ++thread_counter)); @@ -191,5 +191,5 @@ void* BasicThread::launcher(void *arg) thread->Done(); - return 0; + return nullptr; } diff --git a/src/threading/MsgThread.cc b/src/threading/MsgThread.cc index f662d0a46c..2b6ef01ead 100644 --- a/src/threading/MsgThread.cc +++ b/src/threading/MsgThread.cc @@ -172,7 +172,7 @@ bool ReporterMessage::Process() return true; } -MsgThread::MsgThread() : BasicThread(), queue_in(this, 0), queue_out(0, this) +MsgThread::MsgThread() : BasicThread(), queue_in(this, nullptr), queue_out(nullptr, this) { cnt_sent_in = cnt_sent_out = 0; main_finished = false; @@ -367,7 +367,7 @@ BasicOutputMessage* MsgThread::RetrieveOut() { BasicOutputMessage* msg = queue_out.Get(); if ( ! msg ) - return 0; + return nullptr; DBG_LOG(DBG_THREADING, "Retrieved '%s' from %s", msg->Name(), Name()); @@ -379,7 +379,7 @@ BasicInputMessage* MsgThread::RetrieveIn() BasicInputMessage* msg = queue_in.Get(); if ( ! msg ) - return 0; + return nullptr; #ifdef DEBUG string s = Fmt("Retrieved '%s' in %s", msg->Name(), Name()); diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index bd85b846f9..b04549f0b6 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -26,7 +26,7 @@ bool Field::Read(SerializationFormat* fmt) secondary_name = copy_string(tmp_secondary_name.c_str()); } else - secondary_name = 0; + secondary_name = nullptr; bool success = (fmt->Read(&tmp_name, "name") && fmt->Read(&t, "type") diff --git a/src/threading/SerialTypes.h b/src/threading/SerialTypes.h index dbd3635b94..628c3b40f7 100644 --- a/src/threading/SerialTypes.h +++ b/src/threading/SerialTypes.h @@ -31,16 +31,16 @@ struct Field { * Constructor. */ Field(const char* name, const char* secondary_name, TypeTag type, TypeTag subtype, bool optional) - : name(name ? copy_string(name) : 0), - secondary_name(secondary_name ? copy_string(secondary_name) : 0), + : name(name ? copy_string(name) : nullptr), + secondary_name(secondary_name ? copy_string(secondary_name) : nullptr), type(type), subtype(subtype), optional(optional) { } /** * Copy constructor. */ Field(const Field& other) - : name(other.name ? copy_string(other.name) : 0), - secondary_name(other.secondary_name ? copy_string(other.secondary_name) : 0), + : name(other.name ? copy_string(other.name) : nullptr), + secondary_name(other.secondary_name ? copy_string(other.secondary_name) : nullptr), type(other.type), subtype(other.subtype), optional(other.optional) { } ~Field() diff --git a/src/threading/formatters/Ascii.cc b/src/threading/formatters/Ascii.cc index ce8d5461f6..a5337dac1e 100644 --- a/src/threading/formatters/Ascii.cc +++ b/src/threading/formatters/Ascii.cc @@ -214,7 +214,7 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag threading::Value* val = new threading::Value(type, subtype, true); const char* start = s.c_str(); - char* end = 0; + char* end = nullptr; errno = 0; size_t pos; @@ -411,7 +411,7 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag } threading::Value* newval = ParseValue(element, name, subtype); - if ( newval == 0 ) + if ( newval == nullptr ) { GetThread()->Warning("Error while reading set or vector"); error = true; @@ -429,7 +429,7 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag if ( ! error && (s.empty() || *s.rbegin() == separators.set_separator[0]) ) { lvals[pos] = ParseValue("", name, subtype); - if ( lvals[pos] == 0 ) + if ( lvals[pos] == nullptr ) { GetThread()->Warning("Error while trying to add empty set element"); goto parse_error; @@ -470,7 +470,7 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag parse_error: delete val; - return 0; + return nullptr; } bool Ascii::CheckNumberError(const char* start, const char* end) const