[Mesa-dev] [PATCH 07/13] mesa: add extra null checks in vbo_rebase_prims()

Matt Turner mattst88 at gmail.com
Wed Mar 12 14:57:05 PDT 2014


On Wed, Mar 12, 2014 at 2:11 PM, Juha-Pekka Heikkila
<juhapekka.heikkila at gmail.com> wrote:
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
>  src/mesa/vbo/vbo_rebase.c | 25 ++++++++++++++++++++++---
>  1 file changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/src/mesa/vbo/vbo_rebase.c b/src/mesa/vbo/vbo_rebase.c
> index f3fe5f7..7aa8d08 100644
> --- a/src/mesa/vbo/vbo_rebase.c
> +++ b/src/mesa/vbo/vbo_rebase.c
> @@ -60,10 +60,15 @@ static void *rebase_##TYPE( const void *ptr,                        \
>  {                                                              \
>     const TYPE *in = (TYPE *)ptr;                               \
>     TYPE *tmp_indices = malloc(count * sizeof(TYPE));   \
> -   GLuint i;                                                   \
> +   if (tmp_indices != NULL) {                                  \
> +      GLuint i;                                                \
>                                                                 \
> -   for (i = 0; i < count; i++)                                 \
> -      tmp_indices[i] = in[i] - min_index;                      \
> +      for (i = 0; i < count; i++)                              \
> +         tmp_indices[i] = in[i] - min_index;                   \
> +   }                                                           \
> +   else {                                                      \
> +      _mesa_error_no_memory(__FUNCTION__);                     \
> +   }                                                           \

I'd probably check malloc's return value and return NULL if it failed
and avoid indenting the for loop.


More information about the mesa-dev mailing list