From e122bdca298221970d2df96b15113666a4afd2fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Wed, 13 Nov 2024 13:35:23 +0900 Subject: [PATCH 1/2] Fix `port_getn` calling. --- src/backend/libc/event/syscalls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/libc/event/syscalls.rs b/src/backend/libc/event/syscalls.rs index 272226faf..24e020faf 100644 --- a/src/backend/libc/event/syscalls.rs +++ b/src/backend/libc/event/syscalls.rs @@ -319,7 +319,7 @@ pub(crate) fn port_getn( ret(c::port_getn( borrowed_fd(port), events.as_mut_ptr().cast(), - events.len().try_into().unwrap(), + events.capacity().try_into().unwrap(), &mut nget, timeout, ))?; From d5dbc08641ffca06dc8df169a3f54e491d5aef58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Wed, 13 Nov 2024 13:39:36 +0900 Subject: [PATCH 2/2] Return immediately if the vector's capacity is 0. --- src/backend/libc/event/syscalls.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backend/libc/event/syscalls.rs b/src/backend/libc/event/syscalls.rs index 24e020faf..def689ebd 100644 --- a/src/backend/libc/event/syscalls.rs +++ b/src/backend/libc/event/syscalls.rs @@ -314,6 +314,9 @@ pub(crate) fn port_getn( events: &mut Vec, mut nget: u32, ) -> io::Result<()> { + if events.capacity() == 0 { + return Ok(()); + } let timeout = timeout.map_or(null_mut(), as_mut_ptr); unsafe { ret(c::port_getn(