From fb55c8856e73479a3f5af94b3c9985546dda70ac Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Tue, 10 Jun 2025 09:32:23 -0700 Subject: [PATCH] Fix clang-tidy modernize-use-default-member-init warnings in headers --- src/DebugLogger.h | 14 ++++---- src/Expr.cc | 4 +-- src/Expr.h | 8 ++--- src/MMDB.cc | 2 +- src/MMDB.h | 2 +- src/Pipe.h | 8 ++--- src/RuleMatcher.h | 4 +-- src/ScriptCoverageManager.cc | 2 -- src/ScriptCoverageManager.h | 7 ++-- src/SerializationFormat.cc | 5 +-- src/SerializationFormat.h | 18 +++++----- src/Stmt.cc | 2 +- src/Stmt.h | 6 ++-- src/TunnelEncapsulation.h | 4 +-- src/analyzer/protocol/conn-size/ConnSize.cc | 14 +------- src/analyzer/protocol/conn-size/ConnSize.h | 20 +++++------ src/analyzer/protocol/ftp/FTP.cc | 2 -- src/analyzer/protocol/ftp/FTP.h | 7 ++-- src/analyzer/protocol/login/Login.cc | 2 +- src/analyzer/protocol/login/Login.h | 2 +- src/analyzer/protocol/login/NVT.cc | 3 +- src/analyzer/protocol/login/NVT.h | 2 +- src/analyzer/protocol/pia/PIA.cc | 2 +- src/analyzer/protocol/pia/PIA.h | 7 ++-- src/analyzer/protocol/rpc/RPC.cc | 2 +- src/analyzer/protocol/rpc/RPC.h | 4 +-- src/analyzer/protocol/tcp/TCP.cc | 3 +- src/analyzer/protocol/tcp/TCP.h | 4 +-- src/file_analysis/File.cc | 14 +------- src/file_analysis/File.h | 36 +++++++++---------- src/file_analysis/Manager.cc | 7 +--- src/file_analysis/Manager.h | 14 ++++---- src/file_analysis/analyzer/extract/Extract.cc | 1 - src/file_analysis/analyzer/extract/Extract.h | 8 ++--- src/file_analysis/analyzer/hash/Hash.cc | 1 - src/file_analysis/analyzer/hash/Hash.h | 4 +-- src/input/readers/binary/Binary.cc | 2 +- src/input/readers/binary/Binary.h | 8 ++--- src/input/readers/sqlite/SQLite.cc | 3 +- src/input/readers/sqlite/SQLite.h | 14 ++++---- src/logging/WriterBackend.h | 10 +++--- src/logging/writers/sqlite/SQLite.cc | 2 +- src/logging/writers/sqlite/SQLite.h | 8 ++--- src/zeekygen/IdentifierInfo.cc | 1 - src/zeekygen/IdentifierInfo.h | 4 +-- src/zeekygen/Manager.cc | 8 ++--- src/zeekygen/Manager.h | 8 ++--- src/zeekygen/Target.cc | 2 +- src/zeekygen/Target.h | 4 +-- 49 files changed, 134 insertions(+), 185 deletions(-) diff --git a/src/DebugLogger.h b/src/DebugLogger.h index 7bf7e0d1cb..fe8527e04e 100644 --- a/src/DebugLogger.h +++ b/src/DebugLogger.h @@ -68,7 +68,7 @@ namespace detail { class DebugLogger { public: // Output goes to stderr per default. - DebugLogger() : file(nullptr), all(false), verbose(false) {}; + DebugLogger() = default; ~DebugLogger(); void OpenDebugLog(const char* filename = 0); @@ -99,14 +99,14 @@ public: void ShowStreamsHelp(); private: - FILE* file; - bool all; - bool verbose; + FILE* file = nullptr; + bool all = false; + bool verbose = false; struct Stream { - const char* prefix; - int indent; - bool enabled; + const char* prefix = nullptr; + int indent = 0; + bool enabled = false; }; std::set enabled_streams; diff --git a/src/Expr.cc b/src/Expr.cc index 06f142100f..6a9a05fa00 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -2782,7 +2782,7 @@ static void report_field_deprecation(const RecordType* rt, const Expr* e, int fi } FieldExpr::FieldExpr(ExprPtr arg_op, const char* arg_field_name) - : UnaryExpr(EXPR_FIELD, std::move(arg_op)), field_name(util::copy_string(arg_field_name)), td(nullptr), field(0) { + : UnaryExpr(EXPR_FIELD, std::move(arg_op)), field_name(util::copy_string(arg_field_name)) { if ( IsError() ) return; @@ -2863,7 +2863,7 @@ void FieldExpr::ExprDescribe(ODesc* d) const { } HasFieldExpr::HasFieldExpr(ExprPtr arg_op, const char* arg_field_name) - : UnaryExpr(EXPR_HAS_FIELD, std::move(arg_op)), field_name(arg_field_name), field(0) { + : UnaryExpr(EXPR_HAS_FIELD, std::move(arg_op)), field_name(arg_field_name) { if ( IsError() ) return; diff --git a/src/Expr.h b/src/Expr.h index 7dc33d82fa..6613ba7a45 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -1146,8 +1146,8 @@ protected: void ExprDescribe(ODesc* d) const override; const char* field_name; - const TypeDecl* td; - int field; // -1 = attributes + const TypeDecl* td = nullptr; + int field = -1; }; // "rec?$fieldname" is true if the value of $fieldname in rec is not nil. @@ -1171,8 +1171,8 @@ protected: void ExprDescribe(ODesc* d) const override; - const char* field_name; - int field; + const char* field_name = nullptr; + int field = -1; }; class RecordConstructorExpr final : public Expr { diff --git a/src/MMDB.cc b/src/MMDB.cc index 1160409a3e..a4883c573a 100644 --- a/src/MMDB.cc +++ b/src/MMDB.cc @@ -72,7 +72,7 @@ static zeek::ValPtr mmdb_getvalue(MMDB_entry_data_s* entry_data, int status, int return nullptr; } -MMDB::MMDB() : mmdb{}, file_info{}, reported_error{false}, last_check{zeek::run_state::network_time} {} +MMDB::MMDB() : mmdb{}, file_info{}, last_check{zeek::run_state::network_time} {} MMDB::~MMDB() { Close(); } diff --git a/src/MMDB.h b/src/MMDB.h index 0d3af59638..e0dba80194 100644 --- a/src/MMDB.h +++ b/src/MMDB.h @@ -64,7 +64,7 @@ private: std::string filename; MMDB_s mmdb; struct stat file_info; - bool reported_error; // to ensure we emit builtin errors during opening only once. + bool reported_error = false; // to ensure we emit builtin errors during opening only once. double last_check; }; diff --git a/src/Pipe.h b/src/Pipe.h index 9cab4e24b1..8c615d304c 100644 --- a/src/Pipe.h +++ b/src/Pipe.h @@ -57,9 +57,9 @@ public: void UnsetFlags(int flags); private: - int fds[2]; - int flags[2]; - int status_flags[2]; + int fds[2] = {-1, -1}; + int flags[2] = {0}; + int status_flags[2] = {0}; }; /** @@ -119,7 +119,7 @@ public: void Swap() { swapped = ! swapped; } private: - Pipe pipes[2]; + Pipe pipes[2]; // NOLINT(modernize-use-default-member-init) bool swapped = false; }; diff --git a/src/RuleMatcher.h b/src/RuleMatcher.h index bf8d8b8d1e..6302731d87 100644 --- a/src/RuleMatcher.h +++ b/src/RuleMatcher.h @@ -112,13 +112,11 @@ private: friend class RuleMatcher; struct PatternSet { - PatternSet() : re() {} - // If we're above the 'RE_level' (see RuleMatcher), this // expr contains all patterns on this node. If we're on // 'RE_level', it additionally contains all patterns // of any of its children. - Specific_RE_Matcher* re; + Specific_RE_Matcher* re = nullptr; // All the patterns and their rule indices. string_list patterns; diff --git a/src/ScriptCoverageManager.cc b/src/ScriptCoverageManager.cc index a57394b8bf..abe5b2eee1 100644 --- a/src/ScriptCoverageManager.cc +++ b/src/ScriptCoverageManager.cc @@ -20,8 +20,6 @@ using namespace std; namespace zeek::detail { -ScriptCoverageManager::ScriptCoverageManager() : ignoring(0), delim('\t') {} - void ScriptCoverageManager::AddStmt(Stmt* s) { if ( ignoring != 0 || analysis_options.gen_ZAM ) return; diff --git a/src/ScriptCoverageManager.h b/src/ScriptCoverageManager.h index 6cd6852753..9bf7d558c1 100644 --- a/src/ScriptCoverageManager.h +++ b/src/ScriptCoverageManager.h @@ -19,9 +19,6 @@ using ObjPtr = IntrusivePtr; */ class ScriptCoverageManager { public: - ScriptCoverageManager(); - virtual ~ScriptCoverageManager() = default; - /** * Imports Zeek script Stmt usage information from file pointed to by * environment variable ZEEK_PROFILER_FILE. @@ -64,12 +61,12 @@ private: * Indicates whether new statements will not be considered as part of * coverage statistics because it was marked with the @no-test tag. */ - uint32_t ignoring; + uint32_t ignoring = 0; /** * The character to use to delimit ScriptCoverageManager output files. Default is '\t'. */ - char delim; + char delim = '\t'; /** * This maps Stmt location-desc pairs to the total number of times that diff --git a/src/SerializationFormat.cc b/src/SerializationFormat.cc index ab96b5d4ca..b932e97497 100644 --- a/src/SerializationFormat.cc +++ b/src/SerializationFormat.cc @@ -12,10 +12,7 @@ namespace zeek::detail { -const float SerializationFormat::GROWTH_FACTOR = 2.5; - -SerializationFormat::SerializationFormat() - : output(), output_size(), output_pos(), input(), input_len(), input_pos(), bytes_written(), bytes_read() {} +constexpr float SerializationFormat::GROWTH_FACTOR = 2.5; SerializationFormat::~SerializationFormat() { free(output); } diff --git a/src/SerializationFormat.h b/src/SerializationFormat.h index a0a2391fc9..c501301891 100644 --- a/src/SerializationFormat.h +++ b/src/SerializationFormat.h @@ -20,7 +20,7 @@ namespace detail { // Abstract base class. class SerializationFormat { public: - SerializationFormat(); + SerializationFormat() = default; virtual ~SerializationFormat(); // Unserialization. @@ -88,16 +88,16 @@ protected: static const uint32_t INITIAL_SIZE = 65536; static const float GROWTH_FACTOR; - char* output; - uint32_t output_size; - uint32_t output_pos; + char* output = nullptr; + uint32_t output_size = 0; + uint32_t output_pos = 0; - const char* input; - uint32_t input_len; - uint32_t input_pos; + const char* input = nullptr; + uint32_t input_len = 0; + uint32_t input_pos = 0; - int bytes_written; - int bytes_read; + int bytes_written = 0; + int bytes_read = 0; }; class BinarySerializationFormat final : public SerializationFormat { diff --git a/src/Stmt.cc b/src/Stmt.cc index b72ee06ade..bbcc5a7243 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -642,7 +642,7 @@ void SwitchStmt::Init() { } SwitchStmt::SwitchStmt(ExprPtr index, case_list* arg_cases) - : ExprStmt(STMT_SWITCH, std::move(index)), cases(arg_cases), default_case_idx(-1) { + : ExprStmt(STMT_SWITCH, std::move(index)), cases(arg_cases) { Init(); bool have_exprs = false; diff --git a/src/Stmt.h b/src/Stmt.h index 9fac25752e..cc242170d7 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -220,9 +220,9 @@ protected: // the matching type-based case if it defines one. std::pair FindCaseLabelMatch(const Val* v) const; - case_list* cases; - int default_case_idx; - CompositeHash* comp_hash; + case_list* cases = nullptr; + int default_case_idx = -1; + CompositeHash* comp_hash = nullptr; std::unordered_map case_label_value_map; PDict case_label_hash_map; std::vector> case_label_type_list; diff --git a/src/TunnelEncapsulation.h b/src/TunnelEncapsulation.h index 402e6cca0d..5f00900b40 100644 --- a/src/TunnelEncapsulation.h +++ b/src/TunnelEncapsulation.h @@ -145,7 +145,7 @@ protected: */ class EncapsulationStack { public: - EncapsulationStack() : conns(nullptr) {} + EncapsulationStack() = default; EncapsulationStack(const EncapsulationStack& other) { if ( other.conns ) @@ -241,7 +241,7 @@ public: void Pop(); protected: - std::vector* conns; + std::vector* conns = nullptr; }; } // namespace zeek diff --git a/src/analyzer/protocol/conn-size/ConnSize.cc b/src/analyzer/protocol/conn-size/ConnSize.cc index f80d16a6d1..eeed6ce531 100644 --- a/src/analyzer/protocol/conn-size/ConnSize.cc +++ b/src/analyzer/protocol/conn-size/ConnSize.cc @@ -11,19 +11,7 @@ namespace zeek::analyzer::conn_size { -ConnSize_Analyzer::ConnSize_Analyzer(Connection* c) - : Analyzer("CONNSIZE", c), - orig_bytes(), - resp_bytes(), - orig_pkts(), - resp_pkts(), - orig_bytes_thresh(), - resp_bytes_thresh(), - orig_pkts_thresh(), - resp_pkts_thresh(), - duration_thresh() { - start_time = c->StartTime(); -} +ConnSize_Analyzer::ConnSize_Analyzer(Connection* c) : Analyzer("CONNSIZE", c) { start_time = c->StartTime(); } void ConnSize_Analyzer::Init() { Analyzer::Init(); diff --git a/src/analyzer/protocol/conn-size/ConnSize.h b/src/analyzer/protocol/conn-size/ConnSize.h index 2ba0aacfbe..268cba8d66 100644 --- a/src/analyzer/protocol/conn-size/ConnSize.h +++ b/src/analyzer/protocol/conn-size/ConnSize.h @@ -32,18 +32,18 @@ protected: void ThresholdEvent(EventHandlerPtr f, uint64_t threshold, bool is_orig); - uint64_t orig_bytes; - uint64_t resp_bytes; - uint64_t orig_pkts; - uint64_t resp_pkts; + uint64_t orig_bytes = 0; + uint64_t resp_bytes = 0; + uint64_t orig_pkts = 0; + uint64_t resp_pkts = 0; - uint64_t orig_bytes_thresh; - uint64_t resp_bytes_thresh; - uint64_t orig_pkts_thresh; - uint64_t resp_pkts_thresh; + uint64_t orig_bytes_thresh = 0; + uint64_t resp_bytes_thresh = 0; + uint64_t orig_pkts_thresh = 0; + uint64_t resp_pkts_thresh = 0; - double start_time; - double duration_thresh; + double start_time = 0.0; + double duration_thresh = 0.0; }; // Exposed to make it available to script optimization. diff --git a/src/analyzer/protocol/ftp/FTP.cc b/src/analyzer/protocol/ftp/FTP.cc index 53be3f0452..2c34af6946 100644 --- a/src/analyzer/protocol/ftp/FTP.cc +++ b/src/analyzer/protocol/ftp/FTP.cc @@ -14,8 +14,6 @@ namespace zeek::analyzer::ftp { FTP_Analyzer::FTP_Analyzer(Connection* conn) : analyzer::tcp::TCP_ApplicationAnalyzer("FTP", conn) { - pending_reply = 0; - nvt_orig = new analyzer::login::NVT_Analyzer(conn, true); nvt_orig->SetIsNULSensitive(true); nvt_orig->SetCRLFAsEOL(LF_as_EOL); diff --git a/src/analyzer/protocol/ftp/FTP.h b/src/analyzer/protocol/ftp/FTP.h index c0bae38dde..00950782f0 100644 --- a/src/analyzer/protocol/ftp/FTP.h +++ b/src/analyzer/protocol/ftp/FTP.h @@ -22,7 +22,7 @@ public: protected: analyzer::login::NVT_Analyzer* nvt_orig; analyzer::login::NVT_Analyzer* nvt_resp; - uint32_t pending_reply; // code associated with multi-line reply, or 0 + uint32_t pending_reply = 0; // code associated with multi-line reply, or 0 std::string auth_requested; // AUTH method requested bool tls_active = false; // starttls active }; @@ -36,8 +36,7 @@ protected: */ class FTP_ADAT_Analyzer final : public analyzer::SupportAnalyzer { public: - FTP_ADAT_Analyzer(Connection* conn, bool arg_orig) - : SupportAnalyzer("FTP_ADAT", conn, arg_orig), first_token(true) {} + FTP_ADAT_Analyzer(Connection* conn, bool arg_orig) : SupportAnalyzer("FTP_ADAT", conn, arg_orig) {} void DeliverStream(int len, const u_char* data, bool orig) override; @@ -45,7 +44,7 @@ protected: // Used by the client-side analyzer to tell if it needs to peek at the // initial context token and do sanity checking (i.e. does it look like // a TLS/SSL handshake token). - bool first_token; + bool first_token = true; }; } // namespace zeek::analyzer::ftp diff --git a/src/analyzer/protocol/login/Login.cc b/src/analyzer/protocol/login/Login.cc index c3b9f74c9d..00c3a8e4e6 100644 --- a/src/analyzer/protocol/login/Login.cc +++ b/src/analyzer/protocol/login/Login.cc @@ -24,7 +24,7 @@ static RE_Matcher* re_login_timeouts; static RE_Matcher* init_RE(ListVal* l); Login_Analyzer::Login_Analyzer(const char* name, Connection* conn) - : analyzer::tcp::TCP_ApplicationAnalyzer(name, conn), user_text() { + : analyzer::tcp::TCP_ApplicationAnalyzer(name, conn) { state = LOGIN_STATE_AUTHENTICATE; num_user_lines_seen = lines_scanned = 0; // Set last_failure_num_user_lines so we will always generate diff --git a/src/analyzer/protocol/login/Login.h b/src/analyzer/protocol/login/Login.h index c746c7bfd1..e8dbf012d8 100644 --- a/src/analyzer/protocol/login/Login.h +++ b/src/analyzer/protocol/login/Login.h @@ -64,7 +64,7 @@ protected: // If we have more user text than this unprocessed, we complain about // excessive typeahead. #define MAX_USER_TEXT 12 - char* user_text[MAX_USER_TEXT]; + char* user_text[MAX_USER_TEXT] = {0}; int user_text_first, user_text_last; // indices into user_text int num_user_text; // number of entries in user_text diff --git a/src/analyzer/protocol/login/NVT.cc b/src/analyzer/protocol/login/NVT.cc index 6de963e323..3d1ef0222f 100644 --- a/src/analyzer/protocol/login/NVT.cc +++ b/src/analyzer/protocol/login/NVT.cc @@ -316,8 +316,7 @@ void TelnetBinaryOption::InconsistentOption(unsigned int /* type */) { } // namespace detail -NVT_Analyzer::NVT_Analyzer(Connection* conn, bool orig) - : analyzer::tcp::ContentLine_Analyzer("NVT", conn, orig), options() {} +NVT_Analyzer::NVT_Analyzer(Connection* conn, bool orig) : analyzer::tcp::ContentLine_Analyzer("NVT", conn, orig) {} NVT_Analyzer::~NVT_Analyzer() { for ( int i = 0; i < num_options; ++i ) diff --git a/src/analyzer/protocol/login/NVT.h b/src/analyzer/protocol/login/NVT.h index 3f8a99af88..b3e1a5f8c4 100644 --- a/src/analyzer/protocol/login/NVT.h +++ b/src/analyzer/protocol/login/NVT.h @@ -164,7 +164,7 @@ protected: int encrypting_mode = 0; char* auth_name = nullptr; - TelnetOption* options[NUM_TELNET_OPTIONS]; + TelnetOption* options[NUM_TELNET_OPTIONS] = {nullptr}; int num_options = 0; }; diff --git a/src/analyzer/protocol/pia/PIA.cc b/src/analyzer/protocol/pia/PIA.cc index 884b4a67fe..55a1dbe341 100644 --- a/src/analyzer/protocol/pia/PIA.cc +++ b/src/analyzer/protocol/pia/PIA.cc @@ -14,7 +14,7 @@ namespace zeek::analyzer::pia { -PIA::PIA(analyzer::Analyzer* arg_as_analyzer) : state(INIT), as_analyzer(arg_as_analyzer), conn(), current_packet() {} +PIA::PIA(analyzer::Analyzer* arg_as_analyzer) : as_analyzer(arg_as_analyzer), current_packet() {} PIA::~PIA() { ClearBuffer(&pkt_buffer); } diff --git a/src/analyzer/protocol/pia/PIA.h b/src/analyzer/protocol/pia/PIA.h index 44b4a0e7df..7573b87e54 100644 --- a/src/analyzer/protocol/pia/PIA.h +++ b/src/analyzer/protocol/pia/PIA.h @@ -73,7 +73,8 @@ protected: void PIA_DeliverPacket(int len, const u_char* data, bool is_orig, uint64_t seq, const IP_Hdr* ip, int caplen, bool clear_state); - enum State : uint8_t { INIT, BUFFERING, MATCHING_ONLY, SKIPPING } state; + enum State : uint8_t { INIT, BUFFERING, MATCHING_ONLY, SKIPPING }; + State state = INIT; // Buffers one chunk of data. Used both for packet payload (incl. // sequence numbers for TCP) and chunks of a reassembled stream. @@ -114,8 +115,8 @@ private: // Joint backend for the two public FirstPacket() methods. void FirstPacket(bool is_orig, const std::optional& proto, const IP_Hdr* ip); - analyzer::Analyzer* as_analyzer; - Connection* conn; + analyzer::Analyzer* as_analyzer = nullptr; + Connection* conn = nullptr; DataBlock current_packet; }; diff --git a/src/analyzer/protocol/rpc/RPC.cc b/src/analyzer/protocol/rpc/RPC.cc index f7a1eb67a1..7ecec676e5 100644 --- a/src/analyzer/protocol/rpc/RPC.cc +++ b/src/analyzer/protocol/rpc/RPC.cc @@ -625,7 +625,7 @@ void Contents_RPC::DeliverStream(int len, const u_char* data, bool orig) { } RPC_Analyzer::RPC_Analyzer(const char* name, Connection* conn, detail::RPC_Interpreter* arg_interp) - : analyzer::tcp::TCP_ApplicationAnalyzer(name, conn), interp(arg_interp), orig_rpc(), resp_rpc() { + : analyzer::tcp::TCP_ApplicationAnalyzer(name, conn), interp(arg_interp) { if ( Conn()->ConnTransport() == TRANSPORT_UDP ) ADD_ANALYZER_TIMER(&RPC_Analyzer::ExpireTimer, run_state::network_time + zeek::detail::rpc_timeout, true, zeek::detail::TIMER_RPC_EXPIRE); diff --git a/src/analyzer/protocol/rpc/RPC.h b/src/analyzer/protocol/rpc/RPC.h index 63927ad752..071d011b73 100644 --- a/src/analyzer/protocol/rpc/RPC.h +++ b/src/analyzer/protocol/rpc/RPC.h @@ -250,8 +250,8 @@ protected: detail::RPC_Interpreter* interp; - Contents_RPC* orig_rpc; - Contents_RPC* resp_rpc; + Contents_RPC* orig_rpc = nullptr; + Contents_RPC* resp_rpc = nullptr; }; } // namespace zeek::analyzer::rpc diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index 15275ae8fb..6a5439e371 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -195,8 +195,7 @@ RecordVal* TCPStats_Endpoint::BuildStats() { return stats; } -TCPStats_Analyzer::TCPStats_Analyzer(Connection* c) - : TCP_ApplicationAnalyzer("TCPSTATS", c), orig_stats(), resp_stats() {} +TCPStats_Analyzer::TCPStats_Analyzer(Connection* c) : TCP_ApplicationAnalyzer("TCPSTATS", c) {} TCPStats_Analyzer::~TCPStats_Analyzer() { delete orig_stats; diff --git a/src/analyzer/protocol/tcp/TCP.h b/src/analyzer/protocol/tcp/TCP.h index 74d92ceb16..dbec0a55b6 100644 --- a/src/analyzer/protocol/tcp/TCP.h +++ b/src/analyzer/protocol/tcp/TCP.h @@ -117,8 +117,8 @@ public: protected: void DeliverPacket(int len, const u_char* data, bool is_orig, uint64_t seq, const IP_Hdr* ip, int caplen) override; - TCPStats_Endpoint* orig_stats; - TCPStats_Endpoint* resp_stats; + TCPStats_Endpoint* orig_stats = nullptr; + TCPStats_Endpoint* resp_stats = nullptr; }; } // namespace zeek::analyzer::tcp diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 8b52ddf25b..092d73a8c5 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -77,19 +77,7 @@ void File::StaticInit() { } File::File(const std::string& file_id, const std::string& source_name, Connection* conn, zeek::Tag tag, bool is_orig) - : id(file_id), - val(nullptr), - file_reassembler(nullptr), - stream_offset(0), - reassembly_max_buffer(0), - did_metadata_inference(false), - reassembly_enabled(false), - postpone_timeout(false), - done(false), - seen_bytes(0), - missing_bytes(0), - overflow_bytes(0), - analyzers(this) { + : id(file_id), val(nullptr), analyzers(this) { StaticInit(); DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Creating new File object", file_id.c_str()); diff --git a/src/file_analysis/File.h b/src/file_analysis/File.h index 1fc5bfa1b4..a367edd764 100644 --- a/src/file_analysis/File.h +++ b/src/file_analysis/File.h @@ -314,31 +314,31 @@ protected: static void StaticInit(); protected: - std::string id; /**< A pretty hash that likely identifies file */ - RecordValPtr val; /**< \c fa_file from script layer. */ - FileReassembler* file_reassembler; /**< A reassembler for the file if it's needed. */ - uint64_t stream_offset; /**< The offset of the file which has been forwarded. */ - uint64_t reassembly_max_buffer; /**< Maximum allowed buffer for reassembly. */ - bool did_metadata_inference; /**< Whether the metadata inference has already been attempted. */ - bool reassembly_enabled; /**< Whether file stream reassembly is needed. */ - bool postpone_timeout; /**< Whether postponing timeout is requested. */ - bool done; /**< If this object is about to be deleted. */ - uint64_t seen_bytes; /**< Number of bytes processed for this file. */ - uint64_t missing_bytes; /**< Number of bytes missed for this file. */ - uint64_t overflow_bytes; /**< Number of bytes not delivered. */ - detail::AnalyzerSet analyzers; /**< A set of attached file analyzers. */ - std::list done_analyzers; /**< Analyzers we're done with, remembered here until they - can be safely deleted. */ + std::string id; /**< A pretty hash that likely identifies file */ + RecordValPtr val; /**< \c fa_file from script layer. */ + FileReassembler* file_reassembler = nullptr; /**< A reassembler for the file if it's needed. */ + uint64_t stream_offset = 0; /**< The offset of the file which has been forwarded. */ + uint64_t reassembly_max_buffer = 0; /**< Maximum allowed buffer for reassembly. */ + bool did_metadata_inference = false; /**< Whether the metadata inference has already been attempted. */ + bool reassembly_enabled = false; /**< Whether file stream reassembly is needed. */ + bool postpone_timeout = false; /**< Whether postponing timeout is requested. */ + bool done = false; /**< If this object is about to be deleted. */ + uint64_t seen_bytes = 0; /**< Number of bytes processed for this file. */ + uint64_t missing_bytes = 0; /**< Number of bytes missed for this file. */ + uint64_t overflow_bytes = 0; /**< Number of bytes not delivered. */ + detail::AnalyzerSet analyzers; /**< A set of attached file analyzers. */ + std::list done_analyzers; /**< Analyzers we're done with, remembered here until they + can be safely deleted. */ struct BOF_Buffer { - BOF_Buffer() : full(false), size(0) {} + BOF_Buffer() = default; ~BOF_Buffer() { for ( auto* chunk : chunks ) delete chunk; } - bool full; - uint64_t size; + bool full = false; + uint64_t size = 0; String::CVec chunks; } bof_buffer; /**< Beginning of file buffer. */ diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index d67621c201..43c4abf06d 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -16,12 +16,7 @@ using namespace std; namespace zeek::file_analysis { -Manager::Manager() - : plugin::ComponentManager("Files", "Tag", "AllAnalyzers"), - current_file_id(), - magic_state(), - cumulative_files(0), - max_files(0) {} +Manager::Manager() : plugin::ComponentManager("Files", "Tag", "AllAnalyzers") {} Manager::~Manager() { for ( const auto& [_, tag] : mime_types ) diff --git a/src/file_analysis/Manager.h b/src/file_analysis/Manager.h index bdc850b171..c35a5b4f8b 100644 --- a/src/file_analysis/Manager.h +++ b/src/file_analysis/Manager.h @@ -428,17 +428,17 @@ private: TagSet* LookupMIMEType(const std::string& mtype, bool add_if_not_found); - std::map id_map; /**< Map file ID to file_analysis::File records. */ - std::set ignored; /**< Ignored files. Will be finally removed on EOF. */ - std::string current_file_id; /**< Hash of what get_file_handle event sets. */ - zeek::detail::RuleFileMagicState* magic_state; /**< File magic signature match state. */ - MIMEMap mime_types; /**< Mapping of MIME types to analyzers. */ + std::map id_map; /**< Map file ID to file_analysis::File records. */ + std::set ignored; /**< Ignored files. Will be finally removed on EOF. */ + std::string current_file_id; /**< Hash of what get_file_handle event sets. */ + zeek::detail::RuleFileMagicState* magic_state = nullptr; /**< File magic signature match state. */ + MIMEMap mime_types; /**< Mapping of MIME types to analyzers. */ inline static TableVal* disabled = nullptr; /**< Table of disabled analyzers. */ inline static TableType* tag_set_type = nullptr; /**< Type for set[tag]. */ - size_t cumulative_files; - size_t max_files; + size_t cumulative_files = 0; + size_t max_files = 0; zeek::detail::CompositeHash* analyzer_hash = nullptr; }; diff --git a/src/file_analysis/analyzer/extract/Extract.cc b/src/file_analysis/analyzer/extract/Extract.cc index d5eb6263ac..47b13c7036 100644 --- a/src/file_analysis/analyzer/extract/Extract.cc +++ b/src/file_analysis/analyzer/extract/Extract.cc @@ -16,7 +16,6 @@ Extract::Extract(RecordValPtr args, file_analysis::File* file, std::string arg_f : file_analysis::Analyzer(file_mgr->GetComponentTag("EXTRACT"), std::move(args), file), filename(std::move(arg_filename)), limit(arg_limit), - written(0), limit_includes_missing(arg_limit_includes_missing) { char buf[128]; file_stream = fopen(filename.data(), "wb"); diff --git a/src/file_analysis/analyzer/extract/Extract.h b/src/file_analysis/analyzer/extract/Extract.h index 733bb91527..6a94ff178c 100644 --- a/src/file_analysis/analyzer/extract/Extract.h +++ b/src/file_analysis/analyzer/extract/Extract.h @@ -69,10 +69,10 @@ protected: private: std::string filename; - FILE* file_stream; - uint64_t limit; // the file extraction limit - uint64_t written; // how many bytes we have written so far - bool limit_includes_missing; // do count missing bytes against limit if true + FILE* file_stream = nullptr; + uint64_t limit = 0; // the file extraction limit + uint64_t written = 0; // how many bytes we have written so far + bool limit_includes_missing = false; // do count missing bytes against limit if true }; } // namespace zeek::file_analysis::detail diff --git a/src/file_analysis/analyzer/hash/Hash.cc b/src/file_analysis/analyzer/hash/Hash.cc index 5452448d00..ec44eecaf1 100644 --- a/src/file_analysis/analyzer/hash/Hash.cc +++ b/src/file_analysis/analyzer/hash/Hash.cc @@ -16,7 +16,6 @@ Hash::Hash(RecordValPtr args, file_analysis::File* file, HashVal* hv, StringValP : file_analysis::Analyzer(file_mgr->GetComponentTag(util::to_upper(arg_kind->ToStdString())), std::move(args), file), hash(hv), - fed(false), kind(std::move(arg_kind)) { hash->Init(); } diff --git a/src/file_analysis/analyzer/hash/Hash.h b/src/file_analysis/analyzer/hash/Hash.h index b3a30e3d97..be4e5d85c4 100644 --- a/src/file_analysis/analyzer/hash/Hash.h +++ b/src/file_analysis/analyzer/hash/Hash.h @@ -60,8 +60,8 @@ protected: void Finalize(); private: - HashVal* hash; - bool fed; + HashVal* hash = nullptr; + bool fed = false; StringValPtr kind; }; diff --git a/src/input/readers/binary/Binary.cc b/src/input/readers/binary/Binary.cc index f1a9236551..eb87f8d0e8 100644 --- a/src/input/readers/binary/Binary.cc +++ b/src/input/readers/binary/Binary.cc @@ -15,7 +15,7 @@ namespace zeek::input::reader::detail { streamsize Binary::chunk_size = 0; -Binary::Binary(ReaderFrontend* frontend) : ReaderBackend(frontend), in(nullptr), mtime(0), ino(0), firstrun(true) { +Binary::Binary(ReaderFrontend* frontend) : ReaderBackend(frontend) { if ( ! chunk_size ) { chunk_size = BifConst::InputBinary::chunk_size; diff --git a/src/input/readers/binary/Binary.h b/src/input/readers/binary/Binary.h index d80d055022..8d240e542e 100644 --- a/src/input/readers/binary/Binary.h +++ b/src/input/readers/binary/Binary.h @@ -32,10 +32,10 @@ private: int UpdateModificationTime(); std::string fname; - std::ifstream* in; - time_t mtime; - ino_t ino; - bool firstrun; + std::ifstream* in = nullptr; + time_t mtime = 0; + ino_t ino = 0; + bool firstrun = true; // options set from the script-level. static std::streamsize chunk_size; diff --git a/src/input/readers/sqlite/SQLite.cc b/src/input/readers/sqlite/SQLite.cc index d389168df3..d0ee0e44ca 100644 --- a/src/input/readers/sqlite/SQLite.cc +++ b/src/input/readers/sqlite/SQLite.cc @@ -16,8 +16,7 @@ using zeek::threading::Value; namespace zeek::input::reader::detail { -SQLite::SQLite(ReaderFrontend* frontend) - : ReaderBackend(frontend), fields(), num_fields(), mode(), started(), query(), db(), st() { +SQLite::SQLite(ReaderFrontend* frontend) : ReaderBackend(frontend) { set_separator.assign((const char*)BifConst::LogSQLite::set_separator->Bytes(), BifConst::InputSQLite::set_separator->Len()); diff --git a/src/input/readers/sqlite/SQLite.h b/src/input/readers/sqlite/SQLite.h index 6bd1a3c85a..00b6df89ab 100644 --- a/src/input/readers/sqlite/SQLite.h +++ b/src/input/readers/sqlite/SQLite.h @@ -28,14 +28,14 @@ private: threading::Value* EntryToVal(sqlite3_stmt* st, const threading::Field* field, int pos, int subpos); - const threading::Field* const* fields; // raw mapping - unsigned int num_fields; - int mode; - bool started; + const threading::Field* const* fields = nullptr; // raw mapping + unsigned int num_fields = 0; + int mode = 0; + bool started = false; std::string query; - sqlite3* db; - sqlite3_stmt* st; - threading::formatter::Ascii* io; + sqlite3* db = nullptr; + sqlite3_stmt* st = nullptr; + threading::formatter::Ascii* io = nullptr; std::string set_separator; std::string unset_field; diff --git a/src/logging/WriterBackend.h b/src/logging/WriterBackend.h index f6dc9e9861..8c53ceb54a 100644 --- a/src/logging/WriterBackend.h +++ b/src/logging/WriterBackend.h @@ -60,7 +60,7 @@ public: * * Structure takes ownership of string. */ - const char* path; + const char* path = nullptr; /** * The filter this writer is attached to. @@ -79,17 +79,17 @@ public: /** * The rotation interval as configured for this writer. */ - double rotation_interval; + double rotation_interval = 0.0; /** * The parsed value of log_rotate_base_time in seconds. */ - double rotation_base; + double rotation_base = 0.0; /** * The network time when the writer is created. */ - double network_time; + double network_time = 0.0; /** * A map of key/value pairs corresponding to the relevant @@ -97,7 +97,7 @@ public: */ config_map config; - WriterInfo() : path(nullptr), rotation_interval(0.0), rotation_base(0.0), network_time(0.0) {} + WriterInfo() = default; WriterInfo(const WriterInfo& other) { path = other.path ? util::copy_string(other.path) : nullptr; diff --git a/src/logging/writers/sqlite/SQLite.cc b/src/logging/writers/sqlite/SQLite.cc index d397c2d086..8b80d76eef 100644 --- a/src/logging/writers/sqlite/SQLite.cc +++ b/src/logging/writers/sqlite/SQLite.cc @@ -16,7 +16,7 @@ using zeek::threading::Value; namespace zeek::logging::writer::detail { -SQLite::SQLite(WriterFrontend* frontend) : WriterBackend(frontend), fields(), num_fields(), db(), st() { +SQLite::SQLite(WriterFrontend* frontend) : WriterBackend(frontend) { set_separator.assign((const char*)BifConst::LogSQLite::set_separator->Bytes(), BifConst::LogSQLite::set_separator->Len()); diff --git a/src/logging/writers/sqlite/SQLite.h b/src/logging/writers/sqlite/SQLite.h index 619a3f3d9a..86181037a7 100644 --- a/src/logging/writers/sqlite/SQLite.h +++ b/src/logging/writers/sqlite/SQLite.h @@ -32,11 +32,11 @@ private: int AddParams(threading::Value* val, int pos); std::string GetTableType(int, int); - const threading::Field* const* fields; // raw mapping - unsigned int num_fields; + const threading::Field* const* fields = nullptr; // raw mapping + unsigned int num_fields = 0; - sqlite3* db; - sqlite3_stmt* st; + sqlite3* db = nullptr; + sqlite3_stmt* st = nullptr; std::string set_separator; std::string unset_field; diff --git a/src/zeekygen/IdentifierInfo.cc b/src/zeekygen/IdentifierInfo.cc index 0bce8a49f5..40ad06bbbe 100644 --- a/src/zeekygen/IdentifierInfo.cc +++ b/src/zeekygen/IdentifierInfo.cc @@ -19,7 +19,6 @@ IdentifierInfo::IdentifierInfo(zeek::detail::IDPtr arg_id, ScriptInfo* script, b initial_val(), redefs(), fields(), - last_field_seen(), declaring_script(script), from_redef(redef) { if ( id->GetVal() && (id->IsOption() || id->IsRedefinable()) ) diff --git a/src/zeekygen/IdentifierInfo.h b/src/zeekygen/IdentifierInfo.h index 22fffa768c..e8dbb65e36 100644 --- a/src/zeekygen/IdentifierInfo.h +++ b/src/zeekygen/IdentifierInfo.h @@ -185,8 +185,8 @@ private: ValPtr initial_val; redef_list redefs; record_field_map fields; - RecordField* last_field_seen; - ScriptInfo* declaring_script; + RecordField* last_field_seen = nullptr; + ScriptInfo* declaring_script = nullptr; bool from_redef = false; }; diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index 038a183775..ec285eb460 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -51,18 +51,14 @@ static string RemoveLeadingSpace(const string& s) { } Manager::Manager(const string& arg_config, const string& command) - : disabled(), - comment_buffer(), + : comment_buffer(), comment_buffer_map(), packages(), scripts(), identifiers(), all_info(), - last_identifier_seen(), - incomplete_type(), enum_mappings(), - config(arg_config), - mtime() { + config(arg_config) { if ( getenv("ZEEK_DISABLE_ZEEKYGEN") ) disabled = true; diff --git a/src/zeekygen/Manager.h b/src/zeekygen/Manager.h index 796553b2ad..9fc23990bf 100644 --- a/src/zeekygen/Manager.h +++ b/src/zeekygen/Manager.h @@ -226,7 +226,7 @@ private: IdentifierInfo* CreateIdentifierInfo(zeek::detail::IDPtr id, ScriptInfo* script, bool from_redef = false); - bool disabled; + bool disabled = false; comment_buffer_t comment_buffer; // For whatever next identifier comes in. comment_buffer_map_t comment_buffer_map; // For a particular identifier. InfoMap packages; @@ -234,11 +234,11 @@ private: InfoMap identifiers; InfoMap spicy_modules; std::vector all_info; - IdentifierInfo* last_identifier_seen; - IdentifierInfo* incomplete_type; + IdentifierInfo* last_identifier_seen = nullptr; + IdentifierInfo* incomplete_type = nullptr; std::map enum_mappings; // enum id -> enum type id Config config; - time_t mtime; + time_t mtime = 0; }; template diff --git a/src/zeekygen/Target.cc b/src/zeekygen/Target.cc index 66ea327823..1f24149bd9 100644 --- a/src/zeekygen/Target.cc +++ b/src/zeekygen/Target.cc @@ -189,7 +189,7 @@ static vector filter_matches(const vector& from, Target* t) { return rval; } -TargetFile::TargetFile(string arg_name) : name(std::move(arg_name)), f() { +TargetFile::TargetFile(string arg_name) : name(std::move(arg_name)) { if ( name.find('/') != string::npos ) { string dir = util::SafeDirname(name).result; diff --git a/src/zeekygen/Target.h b/src/zeekygen/Target.h index 6fa90018b0..a7a5b346e4 100644 --- a/src/zeekygen/Target.h +++ b/src/zeekygen/Target.h @@ -35,8 +35,8 @@ struct TargetFile { */ ~TargetFile(); - std::string name; /**< File name. */ - FILE* f; /**< File stream. */ + std::string name; /**< File name. */ + FILE* f = nullptr; /**< File stream. */ }; /**