]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #3805: src: change a few operator bool functions to named functions
authorBrian Morris (bmorris2) <bmorris2@cisco.com>
Thu, 13 Apr 2023 15:34:52 +0000 (15:34 +0000)
committerBrian Morris (bmorris2) <bmorris2@cisco.com>
Thu, 13 Apr 2023 15:34:52 +0000 (15:34 +0000)
Merge in SNORT/snort3 from ~BMORRIS2/snort3:cppcheck_operator to master

Squashed commit of the following:

commit cf6f1f58a76a597302628847200369d912d890db
Author: Brian Morris <bmorris2@cisco.com>
Date:   Wed Apr 12 15:52:18 2023 +0000

    src: change a few operator bool functions to named functions

src/detection/treenodes.h
src/profiler/profiler.cc
src/profiler/rule_profiler.cc
src/profiler/time_profiler.cc
src/profiler/time_profiler_defs.h

index 8291e223cb1dfcc2e12e4576433382fb74489a00..0605f96615cc3537a650f38024878cf0da9f6d85 100644 (file)
@@ -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; }
 };
 
index b89235f42ea80378e7b4bd315ef50ebbedb764b9..1760e8007795bafd9957f9784e540d17974beb48 100644 (file)
@@ -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 );
         }
 
index 68c4920ceb925f70d31fe9b79505feaebce32c76..cc0a1b967f1013de619c3ee8f9efeaf828116858 100644 (file)
@@ -225,7 +225,7 @@ static std::vector<View> 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" )
index 57f7c037a399ad6d4f390d9a5fa3f02d2e4514ad..471cfb067cd51451be180d8578b0b66d8b91edb8 100644 (file)
@@ -123,7 +123,7 @@ static const ProfilerSorter<View> 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<time_stats::View> 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" )
index a50e1aaade025c4da0d6c4e772589bcfdc6c3b4b..28b70221275fb3a2fe3e324eaf78192dca07ca75 100644 (file)
@@ -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