You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ca...@apache.org on 2007/12/18 19:03:30 UTC

svn commit: r605275 - /logging/log4cxx/trunk/src/main/cpp/socketoutputstream.cpp

Author: carnold
Date: Tue Dec 18 10:03:28 2007
New Revision: 605275

URL: http://svn.apache.org/viewvc?rev=605275&view=rev
Log:
LOGCXX-7: Check for zero sized array and buffer

Modified:
    logging/log4cxx/trunk/src/main/cpp/socketoutputstream.cpp

Modified: logging/log4cxx/trunk/src/main/cpp/socketoutputstream.cpp
URL: http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/socketoutputstream.cpp?rev=605275&r1=605274&r2=605275&view=diff
==============================================================================
--- logging/log4cxx/trunk/src/main/cpp/socketoutputstream.cpp (original)
+++ logging/log4cxx/trunk/src/main/cpp/socketoutputstream.cpp Tue Dec 18 10:03:28 2007
@@ -38,15 +38,19 @@
 }
 
 void SocketOutputStream::flush(Pool& p) {
-   socket->write(&array[0], array.size());
-   array.resize(0);
+   if (array.size() > 0) {
+     socket->write(&array[0], array.size());
+     array.resize(0);
+   }
 }
 
 void SocketOutputStream::write(ByteBuffer& buf, Pool& /* p */ ) {
-  size_t sz = array.size();
-  array.resize(sz + buf.remaining());
-  memcpy(&array[sz], buf.current(), buf.remaining());
-  buf.position(buf.limit());
+  if (buf.remaining() > 0) {
+    size_t sz = array.size();
+    array.resize(sz + buf.remaining());
+    memcpy(&array[sz], buf.current(), buf.remaining());
+    buf.position(buf.limit());
+  }
 }