PistonDevelopers / glutin_window

A Piston window back-end using the Glutin library
MIT License
25 stars 40 forks source link

Fix UB in `make_current` #190

Closed adumbidiot closed 3 years ago

adumbidiot commented 3 years ago

188 doesn't actually fix the core issue, it just papers over it; UB still occurs while zero initializing a type that disallows zero initialization. I believe this version fixes the UB. It performs no zero initialization, instead using std::ptr::read to get a copy, perform the function that consumes it, then write back the result if it succeeded, or the ctx from the error if it failed.

Edit: I also try to catch panics in make_current and abort since there's not much I can do there. I feel like ctx really should just be an Option.

bvssvni commented 3 years ago

Merging this for now and will release a new update shortly.

I agree ctx should be an Option, to avoid unsafe patterns.

adumbidiot commented 3 years ago

Thanks!