From 937b6314c4cd6fa73daeac308fbfcf69b89add56 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 12:10:48 -0300 Subject: agent_list: the page is read through a volatile pointer Without UBSan the compiler at -O1 folds the read and deletes aligned_alloc with it, and the list check counts one allocation short. --- targets/agent_list.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'targets/agent_list.c') diff --git a/targets/agent_list.c b/targets/agent_list.c index 8787638..65c9274 100644 --- a/targets/agent_list.c +++ b/targets/agent_list.c @@ -31,7 +31,10 @@ int main(int argc, char **argv) { void *page = aligned_alloc(4096, 4096); memset(page, 1, 4096); - long sum = ((char *)page)[100] - 1; + // Read through a volatile pointer: at -O1 the compiler otherwise knows + // the answer and deletes the allocation it came from. + volatile char *probe = page; + long sum = probe[100] - 1; while (head) { struct node *node = head; head = node->next; -- cgit v1.3