From: Brian Morris (bmorris2) Date: Thu, 13 Apr 2023 15:34:52 +0000 (+0000) Subject: Pull request #3805: src: change a few operator bool functions to named functions X-Git-Tag: 3.1.60.0~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82bbf7cd083a538c1ee3371f339129c0fe2e1257;p=thirdparty%2Fsnort3.git Pull request #3805: src: change a few operator bool functions to named functions Merge in SNORT/snort3 from ~BMORRIS2/snort3:cppcheck_operator to master Squashed commit of the following: commit cf6f1f58a76a597302628847200369d912d890db Author: Brian Morris Date: Wed Apr 12 15:52:18 2023 +0000 src: change a few operator bool functions to named functions --- diff --git a/src/detection/treenodes.h b/src/detection/treenodes.h index 8291e223c..0605f9661 100644 --- a/src/detection/treenodes.h +++ b/src/detection/treenodes.h @@ -73,7 +73,7 @@ struct OtnState uint64_t latency_timeouts = 0; uint64_t latency_suspends = 0; - operator bool() const + bool is_active() const { return elapsed > 0_ticks || checks > 0; } }; diff --git a/src/profiler/profiler.cc b/src/profiler/profiler.cc index b89235f42..1760e8007 100644 --- a/src/profiler/profiler.cc +++ b/src/profiler/profiler.cc @@ -136,7 +136,7 @@ TEST_CASE( "profile stats", "[profiler]" ) { ProfileStats stats; - CHECK( !stats.time ); + CHECK( false == stats.time.is_active() ); CHECK( !stats.memory.stats ); } @@ -170,7 +170,7 @@ TEST_CASE( "profile stats", "[profiler]" ) { stats.reset(); - CHECK( !stats.time ); + CHECK( false == stats.time.is_active() ); CHECK( !stats.memory.stats ); } diff --git a/src/profiler/rule_profiler.cc b/src/profiler/rule_profiler.cc index 68c4920ce..cc0a1b967 100644 --- a/src/profiler/rule_profiler.cc +++ b/src/profiler/rule_profiler.cc @@ -225,7 +225,7 @@ static std::vector build_entries() consolidate_otn_states(states); auto& state = states[0]; - if ( !state ) + if ( !state.is_active() ) continue; // FIXIT-L should we assert(otn->sigInfo)? @@ -422,7 +422,7 @@ static inline bool operator==(const RuleEntryVector& lhs, const RuleStatsVector& return false; for ( unsigned i = 0; i < lhs.size(); ++i ) - if ( lhs[i].state != rhs[i] ) + if ( lhs[i].state.is_active() != rhs[i].is_active() ) return false; return true; @@ -499,19 +499,19 @@ TEST_CASE( "otn state", "[profiler][rule_profiler]" ) CHECK( state_a.alerts == 0 ); } - SECTION( "bool()" ) + SECTION( "is_active" ) { - CHECK( state_a ); + CHECK( true == state_a.is_active() ); OtnState state_c = OtnState(); - CHECK_FALSE( state_c ); + CHECK( true == state_c.is_active() ); state_c.elapsed = 1_ticks; - CHECK( state_c ); + CHECK( true == state_c.is_active() ); state_c.elapsed = 0_ticks; state_c.checks = 1; - CHECK( state_c ); + CHECK( true == state_c.is_active() ); } } @@ -528,7 +528,7 @@ TEST_CASE( "rule entry", "[profiler][rule_profiler]" ) CHECK( copy.sig_info.gid == entry.sig_info.gid ); CHECK( copy.sig_info.sid == entry.sig_info.sid ); CHECK( copy.sig_info.rev == entry.sig_info.rev ); - CHECK( copy.state == entry.state ); + CHECK( (copy.state.is_active() == entry.state.is_active()) ); } SECTION( "copy construction" ) @@ -537,7 +537,7 @@ TEST_CASE( "rule entry", "[profiler][rule_profiler]" ) CHECK( copy.sig_info.gid == entry.sig_info.gid ); CHECK( copy.sig_info.sid == entry.sig_info.sid ); CHECK( copy.sig_info.rev == entry.sig_info.rev ); - CHECK( copy.state == entry.state ); + CHECK( (copy.state.is_active() == entry.state.is_active()) ); } SECTION( "elapsed" ) diff --git a/src/profiler/time_profiler.cc b/src/profiler/time_profiler.cc index 57f7c037a..471cfb067 100644 --- a/src/profiler/time_profiler.cc +++ b/src/profiler/time_profiler.cc @@ -123,7 +123,7 @@ static const ProfilerSorter sorters[] = }; static bool include_fn(const ProfilerNode& node) -{ return node.get_stats().time; } +{ return node.get_stats().time.is_active(); } static void print_fn(StatsTable& t, const View& v) { @@ -150,7 +150,7 @@ void show_time_profiler_stats(ProfilerNodeMap& nodes, const TimeProfilerConfig& ProfilerBuilder builder(time_stats::include_fn); auto root = builder.build(nodes.get_root()); - if ( root.children.empty() && !root.view.stats ) + if ( root.children.empty() && !root.view.stats.is_active() ) return; const auto& sorter = time_stats::sorters[config.sort]; @@ -334,10 +334,10 @@ TEST_CASE( "time profiler stats", "[profiler][time_profiler]" ) CHECK( stats == TimeProfilerStats() ); } - SECTION( "bool()" ) + SECTION( "is_active" ) { - CHECK( stats ); - CHECK_FALSE( TimeProfilerStats() ); + CHECK( true == stats.is_active() ); + CHECK_FALSE( TimeProfilerStats().is_active() ); } } @@ -357,7 +357,7 @@ TEST_CASE( "time profiler view", "[profiler][time_profiler]" ) { CHECK( view.name == "foo" ); CHECK( view.stats == the_stats.time ); - CHECK_FALSE( view.caller_stats ); + CHECK( false == view.caller_stats.is_active() ); } SECTION( "elapsed" ) @@ -394,7 +394,7 @@ TEST_CASE( "time profiler view", "[profiler][time_profiler]" ) parent.stats = { 24_ticks, 6 }; time_stats::View child(node, &parent); - CHECK( child.caller_stats ); + CHECK( true == child.caller_stats.is_active() ); SECTION( "pct_caller" ) { @@ -471,7 +471,7 @@ TEST_CASE( "time profiler sorting", "[profiler][time_profiler]" ) TEST_CASE( "time profiler time context disabled", "[profiler][time_profiler]" ) { TimeProfilerStats stats; - REQUIRE_FALSE( stats ); + REQUIRE( false == stats.is_active() ); TimeProfilerStats::set_enabled(false); SECTION( "lifetime" ) @@ -505,7 +505,7 @@ TEST_CASE( "time profiler time context disabled", "[profiler][time_profiler]" ) avoid_optimization(); ctx.stop(); - CHECK( !stats ); + CHECK( false == stats.is_active() ); } SECTION( "reentrance" ) @@ -532,7 +532,7 @@ TEST_CASE( "time profiler time context disabled", "[profiler][time_profiler]" ) TEST_CASE( "time profiler time context", "[profiler][time_profiler]" ) { TimeProfilerStats stats; - REQUIRE_FALSE( stats ); + REQUIRE( false == stats.is_active() ); TimeProfilerStats::set_enabled(true); SECTION( "lifetime" ) @@ -566,7 +566,7 @@ TEST_CASE( "time profiler time context", "[profiler][time_profiler]" ) avoid_optimization(); ctx.stop(); - CHECK( stats ); + CHECK( true == stats.is_active() ); } SECTION( "reentrance" ) diff --git a/src/profiler/time_profiler_defs.h b/src/profiler/time_profiler_defs.h index a50e1aaad..28b702212 100644 --- a/src/profiler/time_profiler_defs.h +++ b/src/profiler/time_profiler_defs.h @@ -61,7 +61,7 @@ struct SO_PUBLIC TimeProfilerStats void reset() { elapsed = 0_ticks; checks = 0; } - operator bool() const + bool is_active() const { return ( elapsed > 0_ticks ) || checks; } // reentrancy control