From 184757b3db7c9e3e9853352a6a7edcaa320f1a2f Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Thu, 17 Apr 2025 11:03:57 -0700 Subject: [PATCH] Fix clang-tidy bugprone-inc-dec-in-conditions warnings --- .clang-tidy | 1 + src/analyzer/protocol/ftp/functions.bif | 14 +++++++++++--- src/analyzer/protocol/ident/Ident.cc | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index cfc4d35fc9..5f1732ea4e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -6,4 +6,5 @@ Checks: [-*, bugprone-incorrect-roundings, bugprone-macro-parentheses, bugprone-multi-level-implicit-pointer-conversion, + bugprone-inc-dec-in-conditions, ] diff --git a/src/analyzer/protocol/ftp/functions.bif b/src/analyzer/protocol/ftp/functions.bif index 4f76c95ae1..a016a776a7 100644 --- a/src/analyzer/protocol/ftp/functions.bif +++ b/src/analyzer/protocol/ftp/functions.bif @@ -164,9 +164,17 @@ function parse_ftp_pasv%(str: string%): ftp_port line += 5; // Skip over else if ( line = strchr(s, ','); line != nullptr ) { // Look for comma-separated list. - while ( --line >= s && isdigit(*line) ) - ; // Back up over preceding digits. - ++line; // now points to first digit, or beginning of s + do + { + // Back up over preceding digits. We'll end on the + // first digit or the beginning of s. + --line; + } + while ( line >= s && isdigit(*line) ); + + // Scoot forward one to point at the first digit or at the + // beginning of s. + ++line; } // Make sure we didn't step past the end of the string. diff --git a/src/analyzer/protocol/ident/Ident.cc b/src/analyzer/protocol/ident/Ident.cc index 378f9dafb7..1b6d11e2ba 100644 --- a/src/analyzer/protocol/ident/Ident.cc +++ b/src/analyzer/protocol/ident/Ident.cc @@ -142,7 +142,7 @@ void Ident_Analyzer::DeliverStream(int length, const u_char* data, bool is_orig) const char* sys_end = (comma && comma < colon) ? comma : colon; - while ( --sys_end > sys_type && isspace(*sys_end) ) + for ( ; sys_end > sys_type && isspace(*sys_end); --sys_end ) ; String* sys_type_s = new String((const u_char*)sys_type, sys_end - sys_type + 1, true);