You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2026/05/08 00:26:56 UTC

(logging-log4cxx) branch master updated: Normalize invalid SMTPAppender buffer sizes (#650)

This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


The following commit(s) were added to refs/heads/master by this push:
     new a0c70b33 Normalize invalid SMTPAppender buffer sizes (#650)
a0c70b33 is described below

commit a0c70b33923a8365c84dad93f85c6f687337cd0b
Author: jmestwa-coder <jm...@gmail.com>
AuthorDate: Fri May 8 05:56:51 2026 +0530

    Normalize invalid SMTPAppender buffer sizes (#650)
---
 src/main/cpp/smtpappender.cpp             | 5 +++++
 src/test/cpp/net/smtpappendertestcase.cpp | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/src/main/cpp/smtpappender.cpp b/src/main/cpp/smtpappender.cpp
index 8f8543ad..535e3916 100644
--- a/src/main/cpp/smtpappender.cpp
+++ b/src/main/cpp/smtpappender.cpp
@@ -787,6 +787,11 @@ buffer. By default the size of the cyclic buffer is 512 events.
 */
 void SMTPAppender::setBufferSize(int sz)
 {
+	if (sz < 1)
+	{
+		sz = 1;
+	}
+
 	_priv->bufferSize = sz;
 	_priv->cb.resize(sz);
 }
diff --git a/src/test/cpp/net/smtpappendertestcase.cpp b/src/test/cpp/net/smtpappendertestcase.cpp
index c2934897..2b3797cf 100644
--- a/src/test/cpp/net/smtpappendertestcase.cpp
+++ b/src/test/cpp/net/smtpappendertestcase.cpp
@@ -75,6 +75,7 @@ class SMTPAppenderTestCase : public AppenderSkeletonTestCase
 		LOGUNIT_TEST(testSetOptionThreshold);
 		LOGUNIT_TEST(testTrigger);
 		LOGUNIT_TEST(testInvalid);
+		LOGUNIT_TEST(testNegativeBufferSizeOption);
 //#define LOG4CXX_TEST_EMAIL_AND_SMTP_HOST_ARE_IN_ENVIRONMENT_VARIABLES
 #ifdef LOG4CXX_TEST_EMAIL_AND_SMTP_HOST_ARE_IN_ENVIRONMENT_VARIABLES
 		// This test requires the following environment variables:
@@ -133,6 +134,12 @@ class SMTPAppenderTestCase : public AppenderSkeletonTestCase
 			LOGUNIT_ASSERT(eh->errorReported());
 		}
 
+		void testNegativeBufferSizeOption()
+		{
+			SMTPAppender appender;
+			appender.setOption(LOG4CXX_STR("BUFFERSIZE"), LOG4CXX_STR("-10"));
+			LOGUNIT_ASSERT_EQUAL(1, appender.getBufferSize());
+		}
 
 		void testValid()
 		{