File tree 2 files changed +11
-3
lines changed 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -468,6 +468,8 @@ impl File {
468
468
/// # Errors
469
469
///
470
470
/// This function will return an error if the file is not opened for writing.
471
+ /// Also, std::io::ErrorKind::InvalidInput will be returned if the desired
472
+ /// length would cause an overflow due to the implementation specifics.
471
473
///
472
474
/// # Examples
473
475
///
Original file line number Diff line number Diff line change @@ -557,9 +557,15 @@ impl File {
557
557
return crate :: sys:: android:: ftruncate64 ( self . 0 . raw ( ) , size) ;
558
558
559
559
#[ cfg( not( target_os = "android" ) ) ]
560
- return cvt_r ( || unsafe {
561
- ftruncate64 ( self . 0 . raw ( ) , size as off64_t )
562
- } ) . map ( |_| ( ) ) ;
560
+ {
561
+ use crate :: convert:: TryInto ;
562
+ let size: off64_t = size
563
+ . try_into ( )
564
+ . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: InvalidInput , e) ) ?;
565
+ cvt_r ( || unsafe {
566
+ ftruncate64 ( self . 0 . raw ( ) , size)
567
+ } ) . map ( |_| ( ) )
568
+ }
563
569
}
564
570
565
571
pub fn read ( & self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
You can’t perform that action at this time.
0 commit comments