From ab78d4af79c1b6e2a4647ea1012b47cf7ecdd8ff Mon Sep 17 00:00:00 2001 From: gberkes Date: Wed, 7 Aug 2024 13:05:02 +0200 Subject: [PATCH] Refactor: used the init-statement to declare "pos" inside the if statement. C++17 introduced a construct to create and initialize a variable within the condition of if and switch statements, and C++20 added this construct to range-based for loops. Using this new feature simplifies common code patterns and helps in giving variables the right scope. Reference: https://sonarcloud.io/project/issues?open=AZDCieK2zGtqRpL2rnl-&id=owasp-modsecurity_ModSecurity --- src/variables/remote_user.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/variables/remote_user.cc b/src/variables/remote_user.cc index 23bc64877c..550294c70e 100644 --- a/src/variables/remote_user.cc +++ b/src/variables/remote_user.cc @@ -56,8 +56,7 @@ void RemoteUser::evaluate(Transaction *transaction, base64 = Utils::Base64::decode(base64); - const auto pos = base64.find(":"); - if (pos != std::string::npos) { + if (const auto pos{base64.find(":")}; pos != std::string::npos) { transaction->m_variableRemoteUser.assign(std::string(base64, 0, pos)); auto var = std::make_unique(&v->getKeyWithCollection(),