Mesa (10.4): mesa: Ensure that length is set to zero in _mesa_GetProgramBinary
Emil Velikov
evelikov at kemper.freedesktop.org
Fri Mar 6 19:42:33 UTC 2015
Module: Mesa
Branch: 10.4
Commit: f1663a5236db78217f735bca73c6796a2fa11e51
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=f1663a5236db78217f735bca73c6796a2fa11e51
Author: Ian Romanick <ian.d.romanick at intel.com>
Date: Sun Dec 21 12:03:57 2014 -0800
mesa: Ensure that length is set to zero in _mesa_GetProgramBinary
v2: Fix assignment of length. Noticed by Julien Cristau.
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=87516
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Acked-by: Leight Bade <leith at mapbox.com>
(cherry picked from commit 4fd8b3012371a5795a0d272928266c6237e57466)
---
src/mesa/main/shaderapi.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 3451ea2..1fec416 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -1682,16 +1682,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;
}
@@ -1700,12 +1719,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;
More information about the mesa-commit
mailing list