[Mesa-dev] [PATCH] mesa: add assert after calloc before access memory in attrib.c

Ian Romanick idr at freedesktop.org
Wed Nov 27 08:29:20 PST 2013


Adding assertions won't fix the errors found by the static analysis tool
because they don't exist in release builds.  The technical correct way
to deal with memory allocation failures in GL is to generate
GL_OUT_OF_MEMORY and return.

On 11/27/2013 06:53 AM, Juha-Pekka Heikkila wrote:
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
>  src/mesa/main/attrib.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
> index c9332bd..5185f89 100644
> --- a/src/mesa/main/attrib.c
> +++ b/src/mesa/main/attrib.c
> @@ -1488,6 +1488,9 @@ init_array_attrib_data(struct gl_context *ctx,
>  {
>     /* Get a non driver gl_array_object. */
>     attrib->ArrayObj = CALLOC_STRUCT( gl_array_object );
> +
> +   assert(attrib->ArrayObj != NULL);
> +
>     _mesa_initialize_array_object(ctx, attrib->ArrayObj, 0);
>  }
>  
> 



More information about the mesa-dev mailing list