From: Anton Likhtarov Date: Wed, 15 Feb 2017 01:35:35 +0000 (-0800) Subject: Fix undefined behaviour X-Git-Tag: v2017.03.06.00~37 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1ce2015a3da9bd9e9d5ad9837bef3963151b858d;p=folly.git Fix undefined behaviour Summary: memcpy's src cannot be nullptr even if the size is 0. Reviewed By: djwatson Differential Revision: D4560100 fbshipit-source-id: 37cd3ed73f902a136f711a5c1a918258f94d1063 --- diff --git a/folly/io/async/AsyncSSLSocket.cpp b/folly/io/async/AsyncSSLSocket.cpp index 60f297c2..074d1ac3 100644 --- a/folly/io/async/AsyncSSLSocket.cpp +++ b/folly/io/async/AsyncSSLSocket.cpp @@ -1463,8 +1463,13 @@ AsyncSocket::WriteResult AsyncSSLSocket::performWrite( uint32_t nextIndex = i + buffersStolen + 1; bytesStolenFromNextBuffer = std::min(vec[nextIndex].iov_len, minWriteSize_ - len); - memcpy(combinedBuf + len, vec[nextIndex].iov_base, - bytesStolenFromNextBuffer); + if (bytesStolenFromNextBuffer > 0) { + assert(vec[nextIndex].iov_base != nullptr); + ::memcpy( + combinedBuf + len, + vec[nextIndex].iov_base, + bytesStolenFromNextBuffer); + } len += bytesStolenFromNextBuffer; if (bytesStolenFromNextBuffer < vec[nextIndex].iov_len) { // couldn't steal the whole buffer