diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 12:10:48 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 12:10:48 -0300 |
| commit | 937b6314c4cd6fa73daeac308fbfcf69b89add56 (patch) | |
| tree | 008493f890cfec41976d189e0dac557fd8cb4bec /targets/agent_list.c | |
| parent | a10e1691dbe5b944812dc8761a450636bc247e3d (diff) | |
| download | computeranim-937b6314c4cd6fa73daeac308fbfcf69b89add56.tar.gz computeranim-937b6314c4cd6fa73daeac308fbfcf69b89add56.zip | |
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.
Diffstat (limited to 'targets/agent_list.c')
| -rw-r--r-- | targets/agent_list.c | 5 |
1 files changed, 4 insertions, 1 deletions
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; |
