Immediate-Mode-UI / Immediate-Mode-UI/Nuklear
Macros NK_OFFSETOF, NK_CONTAINER_OF and NK_ALIGNOF rely on undefined behavior
- Dominant language
- C
- Stars
- 11.4k
- Forks
- 686
- Avg merge
- 4d 1h
- Merged PRs (30d)
- 3
Description
When compiling with clang-9 with the option `-fsanitize=undefined` the basic nuklear example, I get the runtime errors :
`../code/nuklear.h:19196:30: runtime error: member access within null pointer of type 'union nk_page_data'`
`../code/nuklear.h:19197:34: runtime error: member access within null pointer of type 'struct nk_page_element'`
Indeed, the macros `NK_OFFSETOF`, `NK_CONTAINER_OF`, `NK_ALIGNOF` all dereference a null pointer.
One possibility might be to have a `NK_NO_UB` flag or something so that people who want to catch UB errors don't get them when using nuklear.
Contributor guide
Research direction
Start in nuklear.h around lines 19196-19197 and inspect the definitions and uses of NK_OFFSETOF, NK_CONTAINER_OF, and NK_ALIGNOF. Reproduce the report with the basic Nuklear example under clang-9 and -fsanitize=undefined; done means these macros no longer trigger the reported null-pointer member-access errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100