@@ -8011,14 +8011,14 @@ iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int type)
80118011 * iov = PyMem_New (struct iovec , cnt );
80128012 if (* iov == NULL ) {
80138013 PyErr_NoMemory ();
8014- return total ;
8014+ return -1 ;
80158015 }
80168016
80178017 * buf = PyMem_New (Py_buffer , cnt );
80188018 if (* buf == NULL ) {
80198019 PyMem_Del (* iov );
80208020 PyErr_NoMemory ();
8021- return total ;
8021+ return -1 ;
80228022 }
80238023
80248024 for (i = 0 ; i < cnt ; i ++ ) {
@@ -8043,7 +8043,7 @@ iov_setup(struct iovec **iov, Py_buffer **buf, PyObject *seq, int cnt, int type)
80438043 PyBuffer_Release (& (* buf )[j ]);
80448044 }
80458045 PyMem_Del (* buf );
8046- return 0 ;
8046+ return -1 ;
80478047}
80488048
80498049static void
@@ -8083,14 +8083,17 @@ posix_readv(PyObject *self, PyObject *args)
80838083 }
80848084 cnt = PySequence_Size (seq );
80858085
8086- if (! iov_setup (& iov , & buf , seq , cnt , PyBUF_WRITABLE ))
8086+ if (iov_setup (& iov , & buf , seq , cnt , PyBUF_WRITABLE ) < 0 )
80878087 return NULL ;
80888088
80898089 Py_BEGIN_ALLOW_THREADS
80908090 n = readv (fd , iov , cnt );
80918091 Py_END_ALLOW_THREADS
80928092
80938093 iov_cleanup (iov , buf , cnt );
8094+ if (n < 0 )
8095+ return posix_error ();
8096+
80948097 return PyLong_FromSsize_t (n );
80958098}
80968099#endif
@@ -8216,8 +8219,8 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
82168219 Py_ssize_t i = 0 ; /* Avoid uninitialized warning */
82178220 sf .hdr_cnt = PySequence_Size (headers );
82188221 if (sf .hdr_cnt > 0 &&
8219- ! (i = iov_setup (& (sf .headers ), & hbuf ,
8220- headers , sf .hdr_cnt , PyBUF_SIMPLE )))
8222+ (i = iov_setup (& (sf .headers ), & hbuf ,
8223+ headers , sf .hdr_cnt , PyBUF_SIMPLE )) < 0 )
82218224 return NULL ;
82228225#ifdef __APPLE__
82238226 sbytes += i ;
@@ -8233,8 +8236,8 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
82338236 Py_ssize_t i = 0 ; /* Avoid uninitialized warning */
82348237 sf .trl_cnt = PySequence_Size (trailers );
82358238 if (sf .trl_cnt > 0 &&
8236- ! (i = iov_setup (& (sf .trailers ), & tbuf ,
8237- trailers , sf .trl_cnt , PyBUF_SIMPLE )))
8239+ (i = iov_setup (& (sf .trailers ), & tbuf ,
8240+ trailers , sf .trl_cnt , PyBUF_SIMPLE )) < 0 )
82388241 return NULL ;
82398242#ifdef __APPLE__
82408243 sbytes += i ;
@@ -8475,7 +8478,7 @@ posix_writev(PyObject *self, PyObject *args)
84758478 }
84768479 cnt = PySequence_Size (seq );
84778480
8478- if (! iov_setup (& iov , & buf , seq , cnt , PyBUF_SIMPLE )) {
8481+ if (iov_setup (& iov , & buf , seq , cnt , PyBUF_SIMPLE ) < 0 ) {
84798482 return NULL ;
84808483 }
84818484
@@ -8484,6 +8487,9 @@ posix_writev(PyObject *self, PyObject *args)
84848487 Py_END_ALLOW_THREADS
84858488
84868489 iov_cleanup (iov , buf , cnt );
8490+ if (res < 0 )
8491+ return posix_error ();
8492+
84878493 return PyLong_FromSsize_t (res );
84888494}
84898495#endif
0 commit comments