refactor: remove allow_unsafe_buffers pragma from FD_ZERO (#48811)

refactor: remove allow_unsafe_buffers pragma from FD_ZERO
This commit is contained in:
Shelley Vohr
2025-11-07 11:23:52 +01:00
committed by GitHub
parent bab11f8c7b
commit b6a9f08be1

View File

@@ -2,16 +2,10 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove FD_ZERO and convert code to safer
// constructs.
#pragma allow_unsafe_buffers
#endif
#include "shell/common/node_bindings_mac.h"
#include <errno.h>
#include <sys/select.h>
#include <poll.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/types.h>
@@ -23,24 +17,18 @@ NodeBindingsMac::NodeBindingsMac(BrowserEnvironment browser_env)
void NodeBindingsMac::PollEvents() {
auto* const event_loop = uv_loop();
// uv_backend_timeout returns milliseconds or -1 for infinite wait.
const int backend_fd = uv_backend_fd(event_loop);
const int timeout_ms = uv_backend_timeout(event_loop); // -1 => infinite
struct timeval tv;
int timeout = uv_backend_timeout(event_loop);
if (timeout != -1) {
tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000;
}
struct pollfd pfd;
pfd.fd = backend_fd;
pfd.events = POLLIN;
pfd.revents = 0;
fd_set readset;
int fd = uv_backend_fd(event_loop);
FD_ZERO(&readset);
FD_SET(fd, &readset);
// Wait for new libuv events.
int r;
do {
r = select(fd + 1, &readset, nullptr, nullptr,
timeout == -1 ? nullptr : &tv);
r = poll(&pfd, 1, timeout_ms);
} while (r == -1 && errno == EINTR);
}