Fix clang-tidy modernize-loop-convert findings (LOOP_OVER_ macros)

This commit is contained in:
Tim Wojtulewicz 2025-05-14 12:00:41 -07:00
parent f3588657bf
commit 5d3222cbfe
3 changed files with 66 additions and 68 deletions

View file

@ -2,6 +2,8 @@ Checks: [-*,
bugprone-*, bugprone-*,
performance-*, performance-*,
modernize-loop-convert,
# Enable a very limited number of the cppcoreguidelines checkers. # Enable a very limited number of the cppcoreguidelines checkers.
# See the notes for some of the rest of them below. # See the notes for some of the rest of them below.
cppcoreguidelines-macro-usage, cppcoreguidelines-macro-usage,

View file

@ -116,8 +116,8 @@ Analyzer::~Analyzer() {
assert(finished); assert(finished);
assert(new_children.empty()); assert(new_children.empty());
LOOP_OVER_CHILDREN(i) for ( Analyzer* a : children )
delete *i; delete a;
SupportAnalyzer* next = nullptr; SupportAnalyzer* next = nullptr;
@ -139,9 +139,9 @@ void Analyzer::Init() {}
void Analyzer::InitChildren() { void Analyzer::InitChildren() {
AppendNewChildren(); AppendNewChildren();
LOOP_OVER_CHILDREN(i) { for ( Analyzer* a : children ) {
(*i)->Init(); a->Init();
(*i)->InitChildren(); a->InitChildren();
} }
} }
@ -157,9 +157,9 @@ void Analyzer::Done() {
AppendNewChildren(); AppendNewChildren();
LOOP_OVER_CHILDREN(i) for ( Analyzer* a : children )
if ( ! (*i)->finished ) if ( ! a->finished )
(*i)->Done(); a->Done();
for ( SupportAnalyzer* a = orig_supporters; a; a = a->sibling ) for ( SupportAnalyzer* a = orig_supporters; a; a = a->sibling )
if ( ! a->finished ) if ( ! a->finished )
@ -424,25 +424,25 @@ bool Analyzer::IsPreventedChildAnalyzer(const zeek::Tag& tag) const {
bool Analyzer::HasChildAnalyzer(const zeek::Tag& tag) const { return GetChildAnalyzer(tag) != nullptr; } bool Analyzer::HasChildAnalyzer(const zeek::Tag& tag) const { return GetChildAnalyzer(tag) != nullptr; }
Analyzer* Analyzer::GetChildAnalyzer(const zeek::Tag& tag) const { Analyzer* Analyzer::GetChildAnalyzer(const zeek::Tag& tag) const {
LOOP_OVER_CHILDREN(i) for ( Analyzer* a : children )
if ( (*i)->tag == tag && ! ((*i)->removing || (*i)->finished) ) if ( a->tag == tag && ! (a->removing || a->finished) )
return *i; return a;
LOOP_OVER_GIVEN_CHILDREN(i, new_children) for ( Analyzer* a : new_children )
if ( (*i)->tag == tag && ! ((*i)->removing || (*i)->finished) ) if ( a->tag == tag && ! (a->removing || a->finished) )
return *i; return a;
return nullptr; return nullptr;
} }
Analyzer* Analyzer::GetChildAnalyzer(const std::string& name) const { Analyzer* Analyzer::GetChildAnalyzer(const std::string& name) const {
LOOP_OVER_CHILDREN(i) for ( Analyzer* a : children )
if ( (*i)->GetAnalyzerName() == name && ! ((*i)->removing || (*i)->finished) ) if ( a->GetAnalyzerName() == name && ! (a->removing || a->finished) )
return *i; return a;
LOOP_OVER_GIVEN_CHILDREN(i, new_children) for ( Analyzer* a : new_children )
if ( (*i)->GetAnalyzerName() == name && ! ((*i)->removing || (*i)->finished) ) if ( a->GetAnalyzerName() == name && ! (a->removing || a->finished) )
return *i; return a;
return nullptr; return nullptr;
} }
@ -451,15 +451,13 @@ Analyzer* Analyzer::FindChild(ID arg_id) {
if ( id == arg_id && ! (removing || finished) ) if ( id == arg_id && ! (removing || finished) )
return this; return this;
LOOP_OVER_CHILDREN(i) { for ( Analyzer* a : children ) {
Analyzer* child = (*i)->FindChild(arg_id); if ( Analyzer* child = a->FindChild(arg_id) )
if ( child )
return child; return child;
} }
LOOP_OVER_GIVEN_CHILDREN(i, new_children) { for ( Analyzer* a : new_children ) {
Analyzer* child = (*i)->FindChild(arg_id); if ( Analyzer* child = a->FindChild(arg_id) )
if ( child )
return child; return child;
} }
@ -470,15 +468,13 @@ Analyzer* Analyzer::FindChild(zeek::Tag arg_tag) {
if ( tag == arg_tag && ! (removing || finished) ) if ( tag == arg_tag && ! (removing || finished) )
return this; return this;
LOOP_OVER_CHILDREN(i) { for ( Analyzer* a : children ) {
Analyzer* child = (*i)->FindChild(arg_tag); if ( Analyzer* child = a->FindChild(arg_tag) )
if ( child )
return child; return child;
} }
LOOP_OVER_GIVEN_CHILDREN(i, new_children) { for ( Analyzer* a : new_children ) {
Analyzer* child = (*i)->FindChild(arg_tag); if ( Analyzer* child = a->FindChild(arg_tag) )
if ( child )
return child; return child;
} }
@ -607,11 +603,11 @@ void Analyzer::EndOfData(bool is_orig) {
void Analyzer::FlipRoles() { void Analyzer::FlipRoles() {
DBG_LOG(DBG_ANALYZER, "%s FlipRoles()", fmt_analyzer(this).c_str()); DBG_LOG(DBG_ANALYZER, "%s FlipRoles()", fmt_analyzer(this).c_str());
LOOP_OVER_CHILDREN(i) for ( Analyzer* a : children )
(*i)->FlipRoles(); a->FlipRoles();
LOOP_OVER_GIVEN_CHILDREN(i, new_children) for ( Analyzer* a : new_children )
(*i)->FlipRoles(); a->FlipRoles();
for ( SupportAnalyzer* a = orig_supporters; a; a = a->sibling ) for ( SupportAnalyzer* a = orig_supporters; a; a = a->sibling )
a->FlipRoles(); a->FlipRoles();
@ -707,14 +703,14 @@ void Analyzer::CancelTimers() {
} }
void Analyzer::AppendNewChildren() { void Analyzer::AppendNewChildren() {
LOOP_OVER_GIVEN_CHILDREN(i, new_children) for ( Analyzer* a : new_children )
children.push_back(*i); children.push_back(a);
new_children.clear(); new_children.clear();
} }
void Analyzer::UpdateConnVal(RecordVal* conn_val) { void Analyzer::UpdateConnVal(RecordVal* conn_val) {
LOOP_OVER_CHILDREN(i) for ( Analyzer* a : children )
(*i)->UpdateConnVal(conn_val); a->UpdateConnVal(conn_val);
} }
const RecordValPtr& Analyzer::ConnVal() { return conn->GetVal(); } const RecordValPtr& Analyzer::ConnVal() { return conn->GetVal(); }

View file

@ -43,8 +43,8 @@ TCPSessionAdapter::TCPSessionAdapter(Connection* conn) : packet_analysis::IP::Se
} }
TCPSessionAdapter::~TCPSessionAdapter() { TCPSessionAdapter::~TCPSessionAdapter() {
LOOP_OVER_GIVEN_CHILDREN(i, packet_children) for ( Analyzer* a : packet_children )
delete *i; delete a;
delete orig; delete orig;
delete resp; delete resp;
@ -52,8 +52,8 @@ TCPSessionAdapter::~TCPSessionAdapter() {
void TCPSessionAdapter::Init() { void TCPSessionAdapter::Init() {
Analyzer::Init(); Analyzer::Init();
LOOP_OVER_GIVEN_CHILDREN(i, packet_children) for ( Analyzer* a : packet_children )
(*i)->Init(); a->Init();
} }
void TCPSessionAdapter::Done() { void TCPSessionAdapter::Done() {
@ -62,8 +62,8 @@ void TCPSessionAdapter::Done() {
if ( run_state::terminating && connection_pending && is_active && ! BothClosed() ) if ( run_state::terminating && connection_pending && is_active && ! BothClosed() )
Event(connection_pending); Event(connection_pending);
LOOP_OVER_GIVEN_CHILDREN(i, packet_children) for ( Analyzer* a : packet_children )
(*i)->Done(); a->Done();
orig->Done(); orig->Done();
resp->Done(); resp->Done();
@ -644,9 +644,8 @@ analyzer::Analyzer* TCPSessionAdapter::FindChild(analyzer::ID arg_id) {
if ( child ) if ( child )
return child; return child;
LOOP_OVER_GIVEN_CHILDREN(i, packet_children) { for ( Analyzer* a : packet_children ) {
analyzer::Analyzer* child = (*i)->FindChild(arg_id); if ( analyzer::Analyzer* child = a->FindChild(arg_id) )
if ( child )
return child; return child;
} }
@ -659,9 +658,8 @@ analyzer::Analyzer* TCPSessionAdapter::FindChild(zeek::Tag arg_tag) {
if ( child ) if ( child )
return child; return child;
LOOP_OVER_GIVEN_CHILDREN(i, packet_children) { for ( Analyzer* a : packet_children ) {
analyzer::Analyzer* child = (*i)->FindChild(arg_tag); if ( analyzer::Analyzer* child = a->FindChild(arg_tag) )
if ( child )
return child; return child;
} }
@ -1046,8 +1044,8 @@ void TCPSessionAdapter::UpdateConnVal(RecordVal* conn_val) {
Analyzer::UpdateConnVal(conn_val); Analyzer::UpdateConnVal(conn_val);
// Have to do packet_children ourselves. // Have to do packet_children ourselves.
LOOP_OVER_GIVEN_CHILDREN(i, packet_children) for ( Analyzer* a : packet_children )
(*i)->UpdateConnVal(conn_val); a->UpdateConnVal(conn_val);
} }
void TCPSessionAdapter::AttemptTimer(double /* t */) { void TCPSessionAdapter::AttemptTimer(double /* t */) {
@ -1182,11 +1180,12 @@ FilePtr TCPSessionAdapter::GetContentsFile(unsigned int direction) const {
void TCPSessionAdapter::ConnectionClosed(analyzer::tcp::TCP_Endpoint* endpoint, analyzer::tcp::TCP_Endpoint* peer, void TCPSessionAdapter::ConnectionClosed(analyzer::tcp::TCP_Endpoint* endpoint, analyzer::tcp::TCP_Endpoint* peer,
bool gen_event) { bool gen_event) {
const analyzer::analyzer_list& children(GetChildren()); const analyzer::analyzer_list& children(GetChildren());
LOOP_OVER_CONST_CHILDREN(i)
// Using this type of cast here is nasty (will crash if for ( Analyzer* a : children )
// we inadvertently have a child analyzer that's not a // Using this type of cast here is nasty (will crash if
// TCP_ApplicationAnalyzer), but we have to ... // we inadvertently have a child analyzer that's not a
static_cast<analyzer::tcp::TCP_ApplicationAnalyzer*>(*i)->ConnectionClosed(endpoint, peer, gen_event); // TCP_ApplicationAnalyzer), but we have to ...
static_cast<analyzer::tcp::TCP_ApplicationAnalyzer*>(a)->ConnectionClosed(endpoint, peer, gen_event);
if ( DataPending(endpoint) ) { if ( DataPending(endpoint) ) {
// Don't close out the connection yet, there's still data to // Don't close out the connection yet, there's still data to
@ -1266,9 +1265,10 @@ void TCPSessionAdapter::ConnectionClosed(analyzer::tcp::TCP_Endpoint* endpoint,
void TCPSessionAdapter::ConnectionFinished(bool half_finished) { void TCPSessionAdapter::ConnectionFinished(bool half_finished) {
const analyzer::analyzer_list& children(GetChildren()); const analyzer::analyzer_list& children(GetChildren());
LOOP_OVER_CONST_CHILDREN(i)
// Again, nasty - see TCPSessionAdapter::ConnectionClosed. for ( Analyzer* a : children )
static_cast<analyzer::tcp::TCP_ApplicationAnalyzer*>(*i)->ConnectionFinished(half_finished); // Again, nasty - see TCPSessionAdapter::ConnectionClosed.
static_cast<analyzer::tcp::TCP_ApplicationAnalyzer*>(a)->ConnectionFinished(half_finished);
if ( half_finished ) if ( half_finished )
Event(connection_half_finished); Event(connection_half_finished);
@ -1282,8 +1282,8 @@ void TCPSessionAdapter::ConnectionReset() {
Event(connection_reset); Event(connection_reset);
const analyzer::analyzer_list& children(GetChildren()); const analyzer::analyzer_list& children(GetChildren());
LOOP_OVER_CONST_CHILDREN(i) for ( Analyzer* a : children )
static_cast<analyzer::tcp::TCP_ApplicationAnalyzer*>(*i)->ConnectionReset(); static_cast<analyzer::tcp::TCP_ApplicationAnalyzer*>(a)->ConnectionReset();
is_active = 0; is_active = 0;
} }
@ -1312,8 +1312,8 @@ void TCPSessionAdapter::EndpointEOF(analyzer::tcp::TCP_Reassembler* endp) {
EnqueueConnEvent(connection_EOF, ConnVal(), val_mgr->Bool(endp->IsOrig())); EnqueueConnEvent(connection_EOF, ConnVal(), val_mgr->Bool(endp->IsOrig()));
const analyzer::analyzer_list& children(GetChildren()); const analyzer::analyzer_list& children(GetChildren());
LOOP_OVER_CONST_CHILDREN(i) for ( Analyzer* a : children )
static_cast<analyzer::tcp::TCP_ApplicationAnalyzer*>(*i)->EndpointEOF(endp->IsOrig()); static_cast<analyzer::tcp::TCP_ApplicationAnalyzer*>(a)->EndpointEOF(endp->IsOrig());
if ( close_deferred ) { if ( close_deferred ) {
if ( DataPending(endp->Endpoint()) ) { if ( DataPending(endp->Endpoint()) ) {
@ -1331,8 +1331,8 @@ void TCPSessionAdapter::EndpointEOF(analyzer::tcp::TCP_Reassembler* endp) {
void TCPSessionAdapter::PacketWithRST() { void TCPSessionAdapter::PacketWithRST() {
const analyzer::analyzer_list& children(GetChildren()); const analyzer::analyzer_list& children(GetChildren());
LOOP_OVER_CONST_CHILDREN(i) for ( Analyzer* a : children )
static_cast<analyzer::tcp::TCP_ApplicationAnalyzer*>(*i)->PacketWithRST(); static_cast<analyzer::tcp::TCP_ApplicationAnalyzer*>(a)->PacketWithRST();
} }
void TCPSessionAdapter::CheckPIA_FirstPacket(bool is_orig, const IP_Hdr* ip) { void TCPSessionAdapter::CheckPIA_FirstPacket(bool is_orig, const IP_Hdr* ip) {