@@ -110,12 +110,13 @@ impl FileDesc {
110110 target_os = "vita" ,
111111 target_os = "nuttx"
112112 ) ) ) ]
113- pub fn read_vectored ( & self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
113+ pub fn read_vectored ( & self , mut bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
114+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
114115 let ret = cvt ( unsafe {
115116 libc:: readv (
116117 self . as_raw_fd ( ) ,
117118 bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
118- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
119+ bufs. len ( ) as libc:: c_int ,
119120 )
120121 } ) ?;
121122 Ok ( ret as usize )
@@ -200,12 +201,17 @@ impl FileDesc {
200201 target_os = "netbsd" ,
201202 target_os = "openbsd" , // OpenBSD 2.7
202203 ) ) ]
203- pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
204+ pub fn read_vectored_at (
205+ & self ,
206+ mut bufs : & mut [ IoSliceMut < ' _ > ] ,
207+ offset : u64 ,
208+ ) -> io:: Result < usize > {
209+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
204210 let ret = cvt ( unsafe {
205211 libc:: preadv (
206212 self . as_raw_fd ( ) ,
207213 bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
208- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
214+ bufs. len ( ) as libc:: c_int ,
209215 offset as _ ,
210216 )
211217 } ) ?;
@@ -237,7 +243,11 @@ impl FileDesc {
237243 // passing 64-bits parameters to syscalls, so we fallback to the default
238244 // implementation if `preadv` is not available.
239245 #[ cfg( all( target_os = "android" , target_pointer_width = "64" ) ) ]
240- pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
246+ pub fn read_vectored_at (
247+ & self ,
248+ mut bufs : & mut [ IoSliceMut < ' _ > ] ,
249+ offset : u64 ,
250+ ) -> io:: Result < usize > {
241251 syscall ! (
242252 fn preadv(
243253 fd: libc:: c_int,
@@ -247,19 +257,24 @@ impl FileDesc {
247257 ) -> isize ;
248258 ) ;
249259
260+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
250261 let ret = cvt ( unsafe {
251262 preadv (
252263 self . as_raw_fd ( ) ,
253264 bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
254- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
265+ bufs. len ( ) as libc:: c_int ,
255266 offset as _ ,
256267 )
257268 } ) ?;
258269 Ok ( ret as usize )
259270 }
260271
261272 #[ cfg( all( target_os = "android" , target_pointer_width = "32" ) ) ]
262- pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
273+ pub fn read_vectored_at (
274+ & self ,
275+ mut bufs : & mut [ IoSliceMut < ' _ > ] ,
276+ offset : u64 ,
277+ ) -> io:: Result < usize > {
263278 weak ! (
264279 fn preadv64(
265280 fd: libc:: c_int,
@@ -271,11 +286,12 @@ impl FileDesc {
271286
272287 match preadv64. get ( ) {
273288 Some ( preadv) => {
289+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
274290 let ret = cvt ( unsafe {
275291 preadv (
276292 self . as_raw_fd ( ) ,
277293 bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
278- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
294+ bufs. len ( ) as libc:: c_int ,
279295 offset as _ ,
280296 )
281297 } ) ?;
@@ -295,7 +311,11 @@ impl FileDesc {
295311 // These versions may be newer than the minimum supported versions of OS's we support so we must
296312 // use "weak" linking.
297313 #[ cfg( target_vendor = "apple" ) ]
298- pub fn read_vectored_at ( & self , bufs : & mut [ IoSliceMut < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
314+ pub fn read_vectored_at (
315+ & self ,
316+ mut bufs : & mut [ IoSliceMut < ' _ > ] ,
317+ offset : u64 ,
318+ ) -> io:: Result < usize > {
299319 weak ! (
300320 fn preadv(
301321 fd: libc:: c_int,
@@ -307,11 +327,12 @@ impl FileDesc {
307327
308328 match preadv. get ( ) {
309329 Some ( preadv) => {
330+ IoSliceMut :: limit_slices ( & mut bufs, max_iov ( ) ) ;
310331 let ret = cvt ( unsafe {
311332 preadv (
312333 self . as_raw_fd ( ) ,
313334 bufs. as_mut_ptr ( ) as * mut libc:: iovec as * const libc:: iovec ,
314- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
335+ bufs. len ( ) as libc:: c_int ,
315336 offset as _ ,
316337 )
317338 } ) ?;
@@ -338,12 +359,13 @@ impl FileDesc {
338359 target_os = "vita" ,
339360 target_os = "nuttx"
340361 ) ) ) ]
341- pub fn write_vectored ( & self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
362+ pub fn write_vectored ( & self , mut bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
363+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
342364 let ret = cvt ( unsafe {
343365 libc:: writev (
344366 self . as_raw_fd ( ) ,
345367 bufs. as_ptr ( ) as * const libc:: iovec ,
346- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
368+ bufs. len ( ) as libc:: c_int ,
347369 )
348370 } ) ?;
349371 Ok ( ret as usize )
@@ -407,12 +429,13 @@ impl FileDesc {
407429 target_os = "netbsd" ,
408430 target_os = "openbsd" , // OpenBSD 2.7
409431 ) ) ]
410- pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
432+ pub fn write_vectored_at ( & self , mut bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
433+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
411434 let ret = cvt ( unsafe {
412435 libc:: pwritev (
413436 self . as_raw_fd ( ) ,
414437 bufs. as_ptr ( ) as * const libc:: iovec ,
415- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
438+ bufs. len ( ) as libc:: c_int ,
416439 offset as _ ,
417440 )
418441 } ) ?;
@@ -444,7 +467,7 @@ impl FileDesc {
444467 // passing 64-bits parameters to syscalls, so we fallback to the default
445468 // implementation if `pwritev` is not available.
446469 #[ cfg( all( target_os = "android" , target_pointer_width = "64" ) ) ]
447- pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
470+ pub fn write_vectored_at ( & self , mut bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
448471 syscall ! (
449472 fn pwritev(
450473 fd: libc:: c_int,
@@ -454,19 +477,20 @@ impl FileDesc {
454477 ) -> isize ;
455478 ) ;
456479
480+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
457481 let ret = cvt ( unsafe {
458482 pwritev (
459483 self . as_raw_fd ( ) ,
460484 bufs. as_ptr ( ) as * const libc:: iovec ,
461- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
485+ bufs. len ( ) as libc:: c_int ,
462486 offset as _ ,
463487 )
464488 } ) ?;
465489 Ok ( ret as usize )
466490 }
467491
468492 #[ cfg( all( target_os = "android" , target_pointer_width = "32" ) ) ]
469- pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
493+ pub fn write_vectored_at ( & self , mut bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
470494 weak ! (
471495 fn pwritev64(
472496 fd: libc:: c_int,
@@ -478,11 +502,12 @@ impl FileDesc {
478502
479503 match pwritev64. get ( ) {
480504 Some ( pwritev) => {
505+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
481506 let ret = cvt ( unsafe {
482507 pwritev (
483508 self . as_raw_fd ( ) ,
484509 bufs. as_ptr ( ) as * const libc:: iovec ,
485- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
510+ bufs. len ( ) as libc:: c_int ,
486511 offset as _ ,
487512 )
488513 } ) ?;
@@ -502,7 +527,7 @@ impl FileDesc {
502527 // These versions may be newer than the minimum supported versions of OS's we support so we must
503528 // use "weak" linking.
504529 #[ cfg( target_vendor = "apple" ) ]
505- pub fn write_vectored_at ( & self , bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
530+ pub fn write_vectored_at ( & self , mut bufs : & [ IoSlice < ' _ > ] , offset : u64 ) -> io:: Result < usize > {
506531 weak ! (
507532 fn pwritev(
508533 fd: libc:: c_int,
@@ -514,11 +539,12 @@ impl FileDesc {
514539
515540 match pwritev. get ( ) {
516541 Some ( pwritev) => {
542+ IoSlice :: limit_slices ( & mut bufs, max_iov ( ) ) ;
517543 let ret = cvt ( unsafe {
518544 pwritev (
519545 self . as_raw_fd ( ) ,
520546 bufs. as_ptr ( ) as * const libc:: iovec ,
521- cmp :: min ( bufs. len ( ) , max_iov ( ) ) as libc:: c_int ,
547+ bufs. len ( ) as libc:: c_int ,
522548 offset as _ ,
523549 )
524550 } ) ?;
0 commit comments