Fix clang-tidy bugprone-assignment-in-if-condition warnings

This commit is contained in:
Tim Wojtulewicz 2025-04-15 18:05:29 -07:00
parent 8ce741a7a8
commit 92854e95d3
10 changed files with 28 additions and 25 deletions

View file

@ -1,5 +1,3 @@
Checks: '-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
clang-analyzer-*,
performance-*'
Checks: [-*,
bugprone-assignment-in-if-condition,
]

View file

@ -4082,13 +4082,16 @@ CallExpr::CallExpr(ExprPtr arg_func, ListExprPtr arg_args, bool in_hook, bool _i
util::streq(((NameExpr*)func.get())->Id()->Name(), "fmt") &&
// The following is needed because fmt might not yet
// be bound as a name.
did_builtin_init && (func_val = func->Eval(nullptr)) ) {
did_builtin_init ) {
func_val = func->Eval(nullptr);
if ( func_val ) {
zeek::Func* f = func_val->AsFunc();
if ( f->GetKind() == Func::BUILTIN_FUNC && ! check_built_in_call((BuiltinFunc*)f, this) )
SetError();
}
}
}
}
bool CallExpr::IsPure() const {
if ( IsError() )

View file

@ -203,6 +203,7 @@ static void make_var(const IDPtr& id, TypePtr t, InitClass c, ExprPtr init, std:
}
if ( id->GetType() && id->GetType()->Tag() != TYPE_ERROR && ! id->IsBlank() ) {
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
if ( dt != VAR_REDEF && (! init || ! do_init || (! t && ! (t = init_type(init)))) ) {
id->Error("already defined", init.get());
return;

View file

@ -160,9 +160,9 @@ function parse_ftp_pasv%(str: string%): ftp_port
const char* line = strchr(s, '(');
if ( line )
++line; // move past '('
else if ( (line = strstr(s, "PORT")) )
else if ( line = strstr(s, "PORT"); line != nullptr )
line += 5; // Skip over
else if ( (line = strchr(s, ',')) )
else if ( line = strchr(s, ','); line != nullptr )
{ // Look for comma-separated list.
while ( --line >= s && isdigit(*line) )
; // Back up over preceding digits.

View file

@ -1111,7 +1111,7 @@ const char* HTTP_Analyzer::PrefixMatch(const char* line, const char* end_of_line
const char* HTTP_Analyzer::PrefixWordMatch(const char* line, const char* end_of_line, const char* prefix,
bool ignore_case) {
if ( (line = PrefixMatch(line, end_of_line, prefix, ignore_case)) == nullptr )
if ( line = PrefixMatch(line, end_of_line, prefix, ignore_case); line == nullptr )
return nullptr;
const char* orig_line = line;

View file

@ -341,7 +341,7 @@ bool SSL_Analyzer::TryDecryptApplicationData(int len, const u_char* data, bool i
decrypted.resize(decrypted_len);
int res = 0;
if ( ! (res = EVP_DecryptFinal(ctx, NULL, &res)) ) {
if ( res = EVP_DecryptFinal(ctx, NULL, &res); res == 0 ) {
DBG_LOG(DBG_ANALYZER, "Decryption failed with return code: %d. Invalid key?\n", res);
EVP_CIPHER_CTX_free(ctx);
return false;

View file

@ -66,8 +66,8 @@ TEST_CASE("module_util normalized_module_name") {
}
string normalized_module_name(const char* module_name) {
int mod_len;
if ( (mod_len = strlen(module_name)) >= 2 && streq(module_name + mod_len - 2, "::") )
int mod_len = strlen(module_name);
if ( (mod_len >= 2) && streq(module_name + mod_len - 2, "::") != 0 )
mod_len -= 2;
return {module_name, static_cast<size_t>(mod_len)};

View file

@ -211,9 +211,11 @@ IDPtr find_global__CPP(const char* g) {
RecordTypePtr get_record_type__CPP(const char* record_type_name) {
IDPtr existing_type;
if ( record_type_name && (existing_type = global_scope()->Find(record_type_name)) &&
existing_type->GetType()->Tag() == TYPE_RECORD )
if ( record_type_name ) {
IDPtr existing_type = global_scope()->Find(record_type_name);
if ( existing_type && existing_type->GetType()->Tag() == TYPE_RECORD )
return cast_intrusive<RecordType>(existing_type->GetType());
}
return make_intrusive<RecordType>(new type_decl_list());
}

View file

@ -93,8 +93,7 @@ std::string extract_ip(const std::string& i) {
if ( s.size() > 1 && s.substr(0, 2) == "0x" )
s.erase(0, 2);
size_t pos = 0;
if ( (pos = s.find(']')) != std::string::npos )
if ( size_t pos = s.find(']'); pos != std::string::npos )
s = s.substr(0, pos);
return s;
@ -298,9 +297,9 @@ void hmac_md5(size_t size, const unsigned char* bytes, unsigned char digest[16])
static bool read_random_seeds(const char* read_file, uint32_t* seed,
std::array<uint32_t, zeek::detail::KeyedHash::SEED_INIT_SIZE>& buf) {
FILE* f = nullptr;
FILE* f = fopen(read_file, "r");
if ( ! (f = fopen(read_file, "r")) ) {
if ( ! f ) {
reporter->Warning("Could not open seed file '%s': %s", read_file, strerror(errno));
return false;
}
@ -328,9 +327,9 @@ static bool read_random_seeds(const char* read_file, uint32_t* seed,
static bool write_random_seeds(const char* write_file, uint32_t seed,
std::array<uint32_t, zeek::detail::KeyedHash::SEED_INIT_SIZE>& buf) {
FILE* f = nullptr;
FILE* f = fopen(write_file, "w+");
if ( ! (f = fopen(write_file, "w+")) ) {
if ( ! f ) {
reporter->Warning("Could not create seed file '%s': %s", write_file, strerror(errno));
return false;
}

View file

@ -1018,7 +1018,7 @@ SetupResult setup(int argc, char** argv, Options* zopts) {
}
// Cooperate with nohup(1).
if ( (oldhandler = setsignal(SIGHUP, sig_handler)) != SIG_DFL )
if ( oldhandler = setsignal(SIGHUP, sig_handler); oldhandler != SIG_DFL )
(void)setsignal(SIGHUP, oldhandler);
// If we were priming the DNS cache (i.e. -P was passed as an argument), flush anything