[Mesa-dev] [PATCH 2/3] mesa: Add a missing error check in _mesa_GetProgramBinary

Kenneth Graunke kenneth at whitecape.org
Sat Dec 27 04:42:30 PST 2014


On Sunday, December 21, 2014 12:08:44 PM Ian Romanick wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>
> 
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=87516
> ---
>  src/mesa/main/shaderapi.c | 26 ++++++++++++++++++++------
>  1 file changed, 20 insertions(+), 6 deletions(-)

It doesn't look like you're adding a missing error check (like your commit
message says)...it looks like you're setting *length correctly on error
paths.

With Julian's fix, all three are:
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

> diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
> index 108e3f5..c7e2633 100644
> --- a/src/mesa/main/shaderapi.c
> +++ b/src/mesa/main/shaderapi.c
> @@ -1681,16 +1681,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;
>     }
>  
> @@ -1699,12 +1718,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;
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20141227/fa6d954c/attachment.sig>


More information about the mesa-dev mailing list