Dav1dde / glad

Multi-Language Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specs.
https://glad.dav1d.de/
Other
3.73k stars 440 forks source link

Use a base function pointer instead of a regular pointer #483

Closed kenan-kartal closed 1 month ago

kenan-kartal commented 1 month ago

Passing the function pointers with regular pointers result in undefined behaviour. Before this commit, UBSan Clang Sanitizer catches this issue.

I think casting function pointers back to their original signatures from the base pointer does not result in undefined behaviour. At least UBSan does not complain after these changes.

This commit should not affect existing dependants because it introduces a single type GLADbasefp and it's used to change the return type of existing API only. Better test it though!

Dav1dde commented 1 month ago

This is actually undefined behaviour for all platforms for which casting a function pointer from/to a void * pointer is not defined/correct, but since OpenGL itself relies on this behaviour, it essentially makes it non existent behaviour, you wouldn't use glad on a platform where OpenGL (or any graphics API) does not exist.

But agreed this is not optimal and glad could be better here and I changed this for glad2 (please confirm it is fixed there!). But for glad1 I will not change the behaviour now since this is a breaking change and will require users to add casts.