Skip to content

Commit ab78d4a

Browse files
author
gberkes
committed
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
1 parent 0feaeac commit ab78d4a

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/variables/remote_user.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ void RemoteUser::evaluate(Transaction *transaction,
5656

5757
base64 = Utils::Base64::decode(base64);
5858

59-
const auto pos = base64.find(":");
60-
if (pos != std::string::npos) {
59+
if (const auto pos{base64.find(":")}; pos != std::string::npos) {
6160
transaction->m_variableRemoteUser.assign(std::string(base64, 0, pos));
6261

6362
auto var = std::make_unique<VariableValue>(&v->getKeyWithCollection(),

0 commit comments

Comments
 (0)