@@ -201,9 +201,9 @@ macro_rules! impl_nio_read_buf {
201201 ) ;
202202 if r != -1 {
203203 $crate:: syscall:: reset_errno( ) ;
204- received += r as size_t ;
204+ received += libc :: size_t :: try_from ( r ) . expect ( "r overflow" ) ;
205205 if received >= $len || r == 0 {
206- r = received as ssize_t ;
206+ r = received. try_into ( ) . expect ( "received overflow" ) ;
207207 break ;
208208 }
209209 }
@@ -219,7 +219,7 @@ macro_rules! impl_nio_read_buf {
219219 $fd,
220220 Some ( wait_time)
221221 ) . is_err( ) {
222- r = received as ssize_t ;
222+ r = received. try_into ( ) . expect ( "received overflow" ) ;
223223 break ;
224224 }
225225 } else if error_kind != std:: io:: ErrorKind :: Interrupted {
@@ -262,8 +262,8 @@ macro_rules! impl_nio_read_iovec {
262262 let vec = unsafe {
263263 Vec :: from_raw_parts(
264264 $iov. cast_mut( ) ,
265- $iovcnt as usize ,
266- $iovcnt as usize
265+ $iovcnt. try_into ( ) . expect ( "overflow" ) ,
266+ $iovcnt. try_into ( ) . expect ( "overflow" ) ,
267267 )
268268 } ;
269269 let mut length = 0 ;
@@ -298,17 +298,17 @@ macro_rules! impl_nio_read_iovec {
298298 $( $arg, ) *
299299 ) ;
300300 if r == 0 {
301- r = received as ssize_t ;
301+ r = received. try_into ( ) . expect ( "received overflow" ) ;
302302 std:: mem:: forget( vec) ;
303303 if blocking {
304304 $crate:: syscall:: set_blocking( $fd) ;
305305 }
306306 return r;
307307 } else if r != -1 {
308308 $crate:: syscall:: reset_errno( ) ;
309- received += r as usize ;
309+ received += libc :: size_t :: try_from ( r ) . expect ( "r overflow" ) ;
310310 if received >= length {
311- r = received as ssize_t ;
311+ r = received. try_into ( ) . expect ( "received overflow" ) ;
312312 break ;
313313 }
314314 offset = received. saturating_sub( length) ;
@@ -325,7 +325,7 @@ macro_rules! impl_nio_read_iovec {
325325 $fd,
326326 Some ( wait_time)
327327 ) . is_err( ) {
328- r = received as ssize_t ;
328+ r = received. try_into ( ) . expect ( "received overflow" ) ;
329329 std:: mem:: forget( vec) ;
330330 if blocking {
331331 $crate:: syscall:: set_blocking( $fd) ;
@@ -390,9 +390,9 @@ macro_rules! impl_nio_write_buf {
390390 ) ;
391391 if r != -1 {
392392 $crate:: syscall:: reset_errno( ) ;
393- sent += r as size_t ;
393+ sent += libc :: size_t :: try_from ( r ) . expect ( "r overflow" ) ;
394394 if sent >= $len {
395- r = sent as ssize_t ;
395+ r = sent. try_into ( ) . expect ( "sent overflow" ) ;
396396 break ;
397397 }
398398 }
@@ -408,7 +408,7 @@ macro_rules! impl_nio_write_buf {
408408 $fd,
409409 Some ( wait_time) ,
410410 ) . is_err( ) {
411- r = sent as ssize_t ;
411+ r = sent. try_into ( ) . expect ( "sent overflow" ) ;
412412 break ;
413413 }
414414 } else if error_kind != std:: io:: ErrorKind :: Interrupted {
@@ -451,8 +451,8 @@ macro_rules! impl_nio_write_iovec {
451451 let vec = unsafe {
452452 Vec :: from_raw_parts(
453453 $iov. cast_mut( ) ,
454- $iovcnt as usize ,
455- $iovcnt as usize
454+ $iovcnt. try_into ( ) . expect ( "overflow" ) ,
455+ $iovcnt. try_into ( ) . expect ( "overflow" ) ,
456456 )
457457 } ;
458458 let mut length = 0 ;
@@ -488,9 +488,9 @@ macro_rules! impl_nio_write_iovec {
488488 ) ;
489489 if r != -1 {
490490 $crate:: syscall:: reset_errno( ) ;
491- sent += r as usize ;
491+ sent += libc :: size_t :: try_from ( r ) . expect ( "r overflow" ) ;
492492 if sent >= length {
493- r = sent as ssize_t ;
493+ r = sent. try_into ( ) . expect ( "sent overflow" ) ;
494494 break ;
495495 }
496496 offset = sent. saturating_sub( length) ;
@@ -507,7 +507,7 @@ macro_rules! impl_nio_write_iovec {
507507 $fd,
508508 Some ( wait_time)
509509 ) . is_err( ) {
510- r = sent as ssize_t ;
510+ r = sent. try_into ( ) . expect ( "sent overflow" ) ;
511511 std:: mem:: forget( vec) ;
512512 if blocking {
513513 $crate:: syscall:: set_blocking( $fd) ;
@@ -697,7 +697,7 @@ pub extern "C" fn send_time_limit(fd: c_int) -> u64 {
697697 SEND_TIME_LIMIT . get ( & fd) . map_or_else (
698698 || unsafe {
699699 let mut tv: libc:: timeval = std:: mem:: zeroed ( ) ;
700- let mut len = size_of :: < libc:: timeval > ( ) as libc :: socklen_t ;
700+ let mut len = libc :: socklen_t :: try_from ( size_of :: < libc:: timeval > ( ) ) . expect ( "overflow" ) ;
701701 if libc:: getsockopt (
702702 fd,
703703 libc:: SOL_SOCKET ,
@@ -713,9 +713,14 @@ pub extern "C" fn send_time_limit(fd: c_int) -> u64 {
713713 }
714714 panic ! ( "getsockopt failed: {error}" ) ;
715715 }
716- let mut time_limit = ( tv. tv_sec as u64 )
716+ let mut time_limit = u64:: try_from ( tv. tv_sec )
717+ . expect ( "overflow" )
717718 . saturating_mul ( 1_000_000_000 )
718- . saturating_add ( ( tv. tv_usec as u64 ) . saturating_mul ( 1_000 ) ) ;
719+ . saturating_add (
720+ u64:: try_from ( tv. tv_usec )
721+ . expect ( "overflow" )
722+ . saturating_mul ( 1_000 ) ,
723+ ) ;
719724 if 0 == time_limit {
720725 // 取消超时
721726 time_limit = u64:: MAX ;
@@ -732,7 +737,7 @@ pub extern "C" fn recv_time_limit(fd: c_int) -> u64 {
732737 RECV_TIME_LIMIT . get ( & fd) . map_or_else (
733738 || unsafe {
734739 let mut tv: libc:: timeval = std:: mem:: zeroed ( ) ;
735- let mut len = size_of :: < libc:: timeval > ( ) as libc :: socklen_t ;
740+ let mut len = libc :: socklen_t :: try_from ( size_of :: < libc:: timeval > ( ) ) . expect ( "overflow" ) ;
736741 if libc:: getsockopt (
737742 fd,
738743 libc:: SOL_SOCKET ,
@@ -748,9 +753,14 @@ pub extern "C" fn recv_time_limit(fd: c_int) -> u64 {
748753 }
749754 panic ! ( "getsockopt failed: {error}" ) ;
750755 }
751- let mut time_limit = ( tv. tv_sec as u64 )
756+ let mut time_limit = u64:: try_from ( tv. tv_sec )
757+ . expect ( "overflow" )
752758 . saturating_mul ( 1_000_000_000 )
753- . saturating_add ( ( tv. tv_usec as u64 ) . saturating_mul ( 1_000 ) ) ;
759+ . saturating_add (
760+ u64:: try_from ( tv. tv_usec )
761+ . expect ( "overflow" )
762+ . saturating_mul ( 1_000 ) ,
763+ ) ;
754764 if 0 == time_limit {
755765 // 取消超时
756766 time_limit = u64:: MAX ;
0 commit comments