From 5bfd84a90308ed6372777ff1e2dd5ddc7e5b21d7 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Sat, 14 Jan 2023 16:30:53 -0700 Subject: [PATCH] Fix/simplify some if statement comparisons --- src/Anon.cc | 7 ++++--- src/Type.cc | 2 +- src/Val.cc | 2 +- src/ZeekString.cc | 2 +- src/analyzer/protocol/irc/IRC.cc | 4 ++-- src/analyzer/protocol/netbios/NetbiosSSN.cc | 2 +- src/zeek.bif | 6 +++--- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Anon.cc b/src/Anon.cc index 8bcdd69afd..08f8f370fb 100644 --- a/src/Anon.cc +++ b/src/Anon.cc @@ -276,11 +276,12 @@ AnonymizeIPAddr_A50::Node* AnonymizeIPAddr_A50::make_peer(ipaddr32_t a, Node* n) // the parent of the two new ones. Node* down[2]; - - if ( ! (down[0] = new_node()) ) + down[0] = new_node(); + if ( ! down[0] ) return nullptr; - if ( ! (down[1] = new_node()) ) + down[1] = new_node(); + if ( ! down[1] ) { free_node(down[0]); return nullptr; diff --git a/src/Type.cc b/src/Type.cc index 78a8ec1b0e..05bc7a1faf 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -2066,7 +2066,7 @@ bool same_type(const Type& arg_t1, const Type& arg_t2, bool is_init, bool match_ // If one is a set and one isn't, they shouldn't // be considered the same type. - if ( (t1->IsSet() && ! t2->IsSet()) || (t2->IsSet() && ! t1->IsSet()) ) + if ( t1->IsSet() != t2->IsSet() ) return false; const auto& y1 = t1->Yield(); diff --git a/src/Val.cc b/src/Val.cc index c00fdbfe55..3890e63361 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -1558,7 +1558,7 @@ bool TableVal::Assign(ValPtr index, std::unique_ptr k, ValPtr n { bool is_set = table_type->IsSet(); - if ( (is_set && new_val) || (! is_set && ! new_val) ) + if ( is_set == (bool)new_val ) InternalWarning("bad set/table in TableVal::Assign"); TableEntryVal* new_entry_val = new TableEntryVal(std::move(new_val)); diff --git a/src/ZeekString.cc b/src/ZeekString.cc index bc3c31484b..2e4fc2b23f 100644 --- a/src/ZeekString.cc +++ b/src/ZeekString.cc @@ -148,7 +148,7 @@ void String::Set(std::string_view str) { Reset(); - if ( str.data() ) + if ( ! str.empty() ) { n = str.size(); b = new u_char[n + 1]; diff --git a/src/analyzer/protocol/irc/IRC.cc b/src/analyzer/protocol/irc/IRC.cc index 8ed4999a60..676391160a 100644 --- a/src/analyzer/protocol/irc/IRC.cc +++ b/src/analyzer/protocol/irc/IRC.cc @@ -436,7 +436,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) // Remove nick name. parts.erase(parts.begin()); - if ( parts.size() > 0 && parts[0][0] == ':' ) + if ( parts[0][0] == ':' ) parts[0] = parts[0].substr(1); auto set = make_intrusive(id::string_set); @@ -586,7 +586,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) // Check for DCC messages. if ( message.size() > 3 && message.substr(0, 3) == "DCC" ) { - if ( message.size() > 0 && message[message.size() - 1] == 1 ) + if ( message[message.size() - 1] == 1 ) message = message.substr(0, message.size() - 1); vector parts = SplitWords(message, ' '); diff --git a/src/analyzer/protocol/netbios/NetbiosSSN.cc b/src/analyzer/protocol/netbios/NetbiosSSN.cc index a90f4456b6..e1436224c7 100644 --- a/src/analyzer/protocol/netbios/NetbiosSSN.cc +++ b/src/analyzer/protocol/netbios/NetbiosSSN.cc @@ -187,7 +187,7 @@ void NetbiosSSN_Interpreter::ParseMessageUDP(const u_char* data, int len, bool i void NetbiosSSN_Interpreter::ParseSessionMsg(const u_char* data, int len, bool is_query) { - if ( len < 4 || strncmp((const char*)data, "\xffSMB", 4) ) + if ( len < 4 || strncmp((const char*)data, "\xffSMB", 4) != 0 ) { // This should be an event, too. analyzer->Weird("netbios_raw_session_msg"); diff --git a/src/zeek.bif b/src/zeek.bif index b1c2a15cc0..025eb79985 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -3006,7 +3006,7 @@ function bytestring_to_count%(s: string, is_le: bool &default=F%): count { uint16_t value = 0; - if ( (host_bigendian && is_le) || (! host_bigendian && ! is_le) ) + if ( host_bigendian == is_le ) { char buf[sizeof(uint16_t)]; memset(buf, 0, sizeof(uint16_t)); @@ -3031,7 +3031,7 @@ function bytestring_to_count%(s: string, is_le: bool &default=F%): count char buf[sizeof(uint32_t)]; memset(buf, 0, sizeof(uint32_t)); - if ( (host_bigendian && is_le) || (! host_bigendian && ! is_le) ) + if ( host_bigendian == is_le ) { char *d = &buf[sizeof(uint32_t)-1]; @@ -3061,7 +3061,7 @@ function bytestring_to_count%(s: string, is_le: bool &default=F%): count char buf[sizeof(uint64_t)]; memset(buf, 0, sizeof(uint64_t)); - if ( (host_bigendian && is_le) || (! host_bigendian && ! is_le) ) + if ( host_bigendian == is_le ) { char *d = &buf[sizeof(uint64_t)-1];