From 7ed2d60e0e3ca36c08825f52c6d738a0a2cb2654 Mon Sep 17 00:00:00 2001 From: Raphael Schlarb Date: Wed, 19 Aug 2026 04:12:18 -0500 Subject: [PATCH] fix: guard null deref in th_poll_handle_map_remove Silences -Werror=null-dereference on the swap-erase lookup. --- src/th_poll.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/th_poll.c b/src/th_poll.c index 9d29c0f..04f8f14 100644 --- a/src/th_poll.c +++ b/src/th_poll.c @@ -147,7 +147,10 @@ th_poll_handle_map_remove(th_poll_handle_map* map, int fd) th_poll_fd_to_idx_map_erase(&map->fd_to_idx_map, iter); if (idx != map->size - 1) { th_poll_fd_to_idx_map_iter last = th_poll_fd_to_idx_map_find(&map->fd_to_idx_map, map->handles[map->size - 1]->fd); - last->value = idx; + TH_ASSERT(last && "Last handle's fd must be present in the map"); + if (last) { + last->value = idx; + } map->handles[idx] = map->handles[map->size - 1]; } --map->size;