From f46b721c57b9ccde9ad3de3034f626e0a7607e92 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 7 Jul 2025 13:36:41 -0400 Subject: [PATCH] LibCore: Always reset the polled `revents` field back to 0 One benefit of using `poll` over `select` is that we can re-use the poll structure list. But there's no guarantee that the underlying system will reset the `revents` field back to 0. So let's explicitly do so. --- Libraries/LibCore/System.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Libraries/LibCore/System.cpp b/Libraries/LibCore/System.cpp index 7d0b94a2f7..d48f8a2e39 100644 --- a/Libraries/LibCore/System.cpp +++ b/Libraries/LibCore/System.cpp @@ -739,10 +739,14 @@ ErrorOr readlink(StringView pathname) ErrorOr poll(Span poll_fds, int timeout) { + for (auto& poll_fd : poll_fds) + poll_fd.revents = 0; + auto const rc = ::poll(poll_fds.data(), poll_fds.size(), timeout); if (rc < 0) return Error::from_syscall("poll"sv, errno); - return { rc }; + + return rc; } unsigned hardware_concurrency()