Skip to content

Non null-terminated C strings sended to OpenGL functions.

  • Program started with GHC started like runhaskell does
  • debuggued with gDEBugger (OpenGL debug)

Consider the following code :

borderBind <- get $ programVars "borderColor"
shadowBind <- get $ programVars "shadowColor"
mathBind   <- get $ uniformLocation txtProg "mathAlpha"
alphaBind  <- get $ uniformLocation txtProg "genAlpha"

I'm using it to retrieve the location of some variables in some shaders, the problem is the real value sended to OpenGL : < see image 1 >

They are not null-terminated, and this way, sending some garbage appended at the end of the string.

I've tested a little work-around :

borderBind <- get $ programVars "borderColor\0"
shadowBind <- get $ programVars "shadowColor\0"
mathBind   <- get $ uniformLocation txtProg "mathAlpha\0"
alphaBind  <- get $ uniformLocation txtProg "genAlpha\0"

And this way I'm able to recover the location normally.

<see image2>

After digging, the problem seem to be in Graphics.Rendering.OpenGL.GL.Shaders, with the function withGLStringLen. This function is using withCAStringLen which acording to documentation ( http://haskell.org/ghc/docs/latest/html/libraries/base/Foreign-C-String.html#v%3AwithCAStringLen ) doesn't provide any assurance about the null termination.

Trac metadata
Trac field Value
Version 6.8.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/HGL
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information