From b5b30eb58d793ce5b64da6357db532472c2ed2b0 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Wed, 24 Jan 2024 09:22:35 +0100 Subject: [PATCH] SMTP/BDAT: Fix SonarQube reported issues --- src/analyzer/protocol/smtp/BDAT.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/analyzer/protocol/smtp/BDAT.cc b/src/analyzer/protocol/smtp/BDAT.cc index bd1f8fadf1..630dfe9cbe 100644 --- a/src/analyzer/protocol/smtp/BDAT.cc +++ b/src/analyzer/protocol/smtp/BDAT.cc @@ -104,13 +104,13 @@ void SMTP_BDAT_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig } } - // Start searching for crlf at the end of the old buffer. - std::string::size_type i = buf.size() - 1; + // Start searching for crlf at the end of the old buffer, if any. + std::string::size_type i = buf.size() > 0 ? buf.size() - 1 : 0; buf.append(reinterpret_cast(data), len); std::string::size_type line_start = 0; - for ( i = 0; i < buf.size(); i++ ) { + for ( ; i < buf.size(); i++ ) { if ( i < buf.size() - 1 && buf[i] == '\r' && buf[i + 1] == '\n' ) { // Found a match, buf[line_start, i) is the line we want to Deliver() buf[i] = '\0'; @@ -314,10 +314,9 @@ public: void SubmitAllHeaders(mime::MIME_HeaderList& hlist) override {} void SubmitData(int len, const char* buf) override {} bool RequestBuffer(int* plen, char** pbuf) override { return false; } - void SubmitAllData() {} void SubmitEvent(int event_type, const char* detail) override {} - const auto& DeliverCalls() { return deliver_calls; } + const auto& DeliverCalls() const { return deliver_calls; } private: std::vector> deliver_calls;