mesa: Ensure that length is set to zero in _mesa_GetProgramBinary
authorIan Romanick <ian.d.romanick@intel.com>
Sun, 21 Dec 2014 20:03:57 +0000 (12:03 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Sun, 11 Jan 2015 23:01:06 +0000 (12:01 +1300)
v2: Fix assignment of length.  Noticed by Julien Cristau.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=87516
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Acked-by: Leight Bade <leith@mapbox.com>
src/mesa/main/shaderapi.c

index 784fa5c16a7dca0cc3234324c0b22deebdbd3fa1..656ee112e559b021cfaf6eeae5e6608c128f6c2f 100644 (file)
@@ -1680,16 +1680,35 @@ _mesa_GetProgramBinary(GLuint program, GLsizei bufSize, GLsizei *length,
                        GLenum *binaryFormat, GLvoid *binary)
 {
    struct gl_shader_program *shProg;
+   GLsizei length_dummy;
    GET_CURRENT_CONTEXT(ctx);
 
    shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetProgramBinary");
    if (!shProg)
       return;
 
+   /* The ARB_get_program_binary spec says:
+    *
+    *     "If <length> is NULL, then no length is returned."
+    *
+    * Ensure that length always points to valid storage to avoid multiple NULL
+    * pointer checks below.
+    */
+   if (length != NULL)
+      length = &length_dummy;
+
+
+   /* The ARB_get_program_binary spec says:
+    *
+    *     "When a program object's LINK_STATUS is FALSE, its program binary
+    *     length is zero, and a call to GetProgramBinary will generate an
+    *     INVALID_OPERATION error.
+    */
    if (!shProg->LinkStatus) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
                   "glGetProgramBinary(program %u not linked)",
                   shProg->Name);
+      *length = 0;
       return;
    }
 
@@ -1698,12 +1717,7 @@ _mesa_GetProgramBinary(GLuint program, GLsizei bufSize, GLsizei *length,
       return;
    }
 
-   /* The ARB_get_program_binary spec says:
-    *
-    *     "If <length> is NULL, then no length is returned."
-    */
-   if (length != NULL)
-      *length = 0;
+   *length = 0;
 
    (void) binaryFormat;
    (void) binary;