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
This commit is contained in:
gberkes 2024-08-07 13:05:02 +02:00
parent 0feaeacce5
commit ab78d4af79

View File

@ -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<VariableValue>(&v->getKeyWithCollection(),