Skip to content

fix: undefined behaviour in allocator#260

Open
xydone wants to merge 1 commit intoibireme:masterfrom
xydone:allocator-ub
Open

fix: undefined behaviour in allocator#260
xydone wants to merge 1 commit intoibireme:masterfrom
xydone:allocator-ub

Conversation

@xydone
Copy link
Copy Markdown

@xydone xydone commented Apr 10, 2026

I would like to preface this by saying I have limited experience with high-performance C, so there is a possibility this is intended UB.

I was working on porting yyjson to the Zig build system when I ran into the following error by ubsan when running the test cases:

panic: applying non-zero offset 32 to null pointer
dyn_ctx *ctx = (dyn_ctx *)(void *)(alc + 1);

I have remedied the issue by moving the if(unlikely(!alc)) check before the pointer arithmetic.

Tested on the test suite from the docs, respecting -Wdeclaration-after-statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant