[GHC] #2549: Non null-terminated C strings sended to OpenGL functions.

GHC trac at galois.com
Wed Aug 27 15:37:02 EDT 2008


#2549: Non null-terminated C strings sended to OpenGL functions.
--------------------------+-------------------------------------------------
    Reporter:  Vincent.B  |       Owner:               
        Type:  bug        |      Status:  new          
    Priority:  normal     |   Component:  libraries/HGL
     Version:  6.8.3      |    Severity:  major        
    Keywords:             |    Testcase:               
Architecture:  x86        |          Os:  Windows      
--------------------------+-------------------------------------------------
 * 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.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2549>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list