@@ -8050,14 +8050,14 @@ iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int type)
80508050 * iov = PyMem_New (struct iovec , cnt );
80518051 if (* iov == NULL ) {
80528052 PyErr_NoMemory ();
8053- return total ;
8053+ return -1 ;
80548054 }
80558055
80568056 * buf = PyMem_New (Py_buffer , cnt );
80578057 if (* buf == NULL ) {
80588058 PyMem_Del (* iov );
80598059 PyErr_NoMemory ();
8060- return total ;
8060+ return -1 ;
80618061 }
80628062
80638063 for (i = 0 ; i < cnt ; i ++ ) {
@@ -8082,7 +8082,7 @@ iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int type)
80828082 PyBuffer_Release (& (* buf )[j ]);
80838083 }
80848084 PyMem_Del (* buf );
8085- return 0 ;
8085+ return -1 ;
80868086}
80878087
80888088static void
@@ -8122,14 +8122,17 @@ posix_readv(PyObject *self, PyObject *args)
81228122 }
81238123 cnt = PySequence_Size (seq );
81248124
8125- if (! iov_setup (& iov , & buf , seq , cnt , PyBUF_WRITABLE ))
8125+ if (iov_setup (& iov , & buf , seq , cnt , PyBUF_WRITABLE ) < 0 )
81268126 return NULL ;
81278127
81288128 Py_BEGIN_ALLOW_THREADS
81298129 n = readv (fd , iov , cnt );
81308130 Py_END_ALLOW_THREADS
81318131
81328132 iov_cleanup (iov , buf , cnt );
8133+ if (n < 0 )
8134+ return posix_error ();
8135+
81338136 return PyLong_FromSsize_t (n );
81348137}
81358138#endif
@@ -8254,8 +8257,8 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
82548257 Py_ssize_t i = 0 ; /* Avoid uninitialized warning */
82558258 sf .hdr_cnt = PySequence_Size (headers );
82568259 if (sf .hdr_cnt > 0 &&
8257- ! (i = iov_setup (& (sf .headers ), & hbuf ,
8258- headers , sf .hdr_cnt , PyBUF_SIMPLE )))
8260+ (i = iov_setup (& (sf .headers ), & hbuf ,
8261+ headers , sf .hdr_cnt , PyBUF_SIMPLE )) < 0 )
82598262 return NULL ;
82608263#ifdef __APPLE__
82618264 sbytes += i ;
@@ -8271,8 +8274,8 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
82718274 Py_ssize_t i = 0 ; /* Avoid uninitialized warning */
82728275 sf .trl_cnt = PySequence_Size (trailers );
82738276 if (sf .trl_cnt > 0 &&
8274- ! (i = iov_setup (& (sf .trailers ), & tbuf ,
8275- trailers , sf .trl_cnt , PyBUF_SIMPLE )))
8277+ (i = iov_setup (& (sf .trailers ), & tbuf ,
8278+ trailers , sf .trl_cnt , PyBUF_SIMPLE )) < 0 )
82768279 return NULL ;
82778280#ifdef __APPLE__
82788281 sbytes += i ;
@@ -8483,7 +8486,7 @@ posix_writev(PyObject *self, PyObject *args)
84838486 }
84848487 cnt = PySequence_Size (seq );
84858488
8486- if (! iov_setup (& iov , & buf , seq , cnt , PyBUF_SIMPLE )) {
8489+ if (iov_setup (& iov , & buf , seq , cnt , PyBUF_SIMPLE ) < 0 ) {
84878490 return NULL ;
84888491 }
84898492
@@ -8492,6 +8495,9 @@ posix_writev(PyObject *self, PyObject *args)
84928495 Py_END_ALLOW_THREADS
84938496
84948497 iov_cleanup (iov , buf , cnt );
8498+ if (res < 0 )
8499+ return posix_error ();
8500+
84958501 return PyLong_FromSsize_t (res );
84968502}
84978503#endif
0 commit comments