From c999d29a7b7031fbc827dca740650745d6da0488 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 24 Jul 2014 13:21:02 +0000 Subject: [PATCH] * fhandler_socket.cc (fhandler_socket::send_internal): Fix value of out_len when tweaking the last buffer so out_len is correct in a subsequent if expression. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/fhandler_socket.cc | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 93896c88c..6c8395df3 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2014-07-24 Corinna Vinschen + + * fhandler_socket.cc (fhandler_socket::send_internal): Fix value of + out_len when tweaking the last buffer so out_len is correct in a + subsequent if expression. + 2014-07-21 Corinna Vinschen * thread.cc (pthread::init_mainthread): Initialize thread mutex to diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc index dbcd2619c..793578f39 100644 --- a/winsup/cygwin/fhandler_socket.cc +++ b/winsup/cygwin/fhandler_socket.cc @@ -1701,9 +1701,13 @@ fhandler_socket::send_internal (struct _WSAMSG *wsamsg, int flags) while (out_len < (unsigned) wmem () && (in_off = 0, ++in_idx < wsamsg->dwBufferCount)); /* Tweak len of the last out_buf buffer so the entire number of bytes - is less than wmem (). */ + is (less than or) equal to wmem (). Fix out_len as well since it's + used in a subsequent test expression. */ if (out_len > (unsigned) wmem ()) - out_buf[out_idx - 1].len -= out_len - (unsigned) wmem (); + { + out_buf[out_idx - 1].len -= out_len - (unsigned) wmem (); + out_len = (unsigned) wmem (); + } /* Add the bytes written from the current last buffer to in_off, so in_off points to the next byte to be written from that buffer, or beyond which lets the outper loop skip to the next buffer. */