From 44824755ab68cf0f991e7c80a71f75ad54a95ae2 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 27 Jan 2023 04:40:30 +0000 Subject: Fix clamping the size of the IOVector array. Casting then clamping might result in a weird size here so instead clamp before casting. --- src/inspsocket.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src/inspsocket.cpp') diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index dbb4a790b..92bd064c1 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -212,7 +212,7 @@ ssize_t StreamSocket::ReadToRecvQ(std::string& rq) } /* Don't try to prepare huge blobs of data to send to a blocked socket */ -static constexpr int MYIOV_MAX = IOV_MAX < 128 ? IOV_MAX : 128; +static constexpr size_t MYIOV_MAX = std::min(IOV_MAX, 128); void StreamSocket::DoWrite() { @@ -272,15 +272,8 @@ void StreamSocket::FlushSendQ(SendQueue& sq) int eventChange = FD_WANT_EDGE_WRITE; while (error.empty() && !sq.empty() && eventChange == FD_WANT_EDGE_WRITE) { - // Prepare a writev() call to write all buffers efficiently. This cast is - // safe as we clamp to MYIOV_MAX right away anyway. - int bufcount = static_cast(sq.size()); - - // cap the number of buffers at MYIOV_MAX - if (bufcount > MYIOV_MAX) - { - bufcount = MYIOV_MAX; - } + // Prepare a writev() call to write all buffers efficiently. + int bufcount = static_cast(std::min(sq.size(), MYIOV_MAX)); int rv_max = 0; ssize_t rv; -- cgit v1.3.1-10-gc9f91