haskell-opengl / OpenGL

Haskell bindings to OpenGL
http://www.haskell.org/haskellwiki/OpenGL
BSD 3-Clause "New" or "Revised" License
147 stars 26 forks source link

mitigate "If an error is generated, no change is made to the contents" #72

Closed claudeha closed 9 years ago

claudeha commented 9 years ago

Most glGet* functions don't change change the contents of the buffer if an error is generated. Buffers created with alloca have undefined contents, which if used causes undefined behaviour (eg: allocating a huge chunk of memory if a size is peeked, overwriting unspecified memory if a pointer is peeked).

This patch mitigates the issue to some extent by using with 0 and with nullPtr instead of alloca, so at least the content of the buffer is defined. There are still some places unchanged, this patch concentrates on cases where the result would be used as a size for memory allocations or as a pointer.

The initial bug report was here: https://www.haskell.org/pipermail/hopengl/2015-January/001152.html