[Mesa-dev] Mesa (master): translate_generic: return NULL instead of assert(0) if format not supported

José Fonseca jfonseca at vmware.com
Wed Aug 11 07:48:49 PDT 2010


Note that assert(0) != crash. In a release build the previous code would
never crash, but simply ignore. Now it will crash.

Did you went through all callers of translate_create() and made sure
they cope with a NULL return value? It doesn't look so. Until then I'd
rather see this patch reverted.

Jose


On Wed, 2010-08-11 at 07:28 -0700, Luca Barbieri wrote:
> Module: Mesa
> Branch: master
> Commit: 16b45ca7cefb3432b4133fe9d0b1dbfe3f286131
> URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=16b45ca7cefb3432b4133fe9d0b1dbfe3f286131
> 
> Author: Luca Barbieri <luca at luca-barbieri.com>
> Date:   Wed Aug 11 15:59:43 2010 +0200
> 
> translate_generic: return NULL instead of assert(0) if format not supported
> 
> This gives the caller a chance to recover (or crash anyway otherwise).
> 
> ---
> 
>  .../auxiliary/translate/translate_generic.c        |   15 ++++++---------
>  1 files changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/src/gallium/auxiliary/translate/translate_generic.c b/src/gallium/auxiliary/translate/translate_generic.c
> index 4d19772..809a4e4 100644
> --- a/src/gallium/auxiliary/translate/translate_generic.c
> +++ b/src/gallium/auxiliary/translate/translate_generic.c
> @@ -201,12 +201,6 @@ emit_B8G8R8A8_UNORM( const float *attrib, void *ptr)
>     out[3] = TO_8_UNORM(attrib[3]);
>  }
>  
> -static void 
> -emit_NULL( const float *attrib, void *ptr )
> -{
> -   /* do nothing is the only sensible option */
> -}
> -
>  static emit_func get_emit_func( enum pipe_format format )
>  {
>     switch (format) {
> @@ -343,8 +337,7 @@ static emit_func get_emit_func( enum pipe_format format )
>        return &emit_A8R8G8B8_UNORM;
>  
>     default:
> -      assert(0); 
> -      return &emit_NULL;
> +      return NULL;
>     }
>  }
>  
> @@ -539,8 +532,12 @@ struct translate *translate_generic_create( const struct translate_key *key )
>        tg->attrib[i].instance_divisor = key->element[i].instance_divisor;
>  
>        tg->attrib[i].emit = get_emit_func(key->element[i].output_format);
> +      if(!tg->attrib[i].emit)
> +      {
> +         FREE(tg);
> +         return NULL;
> +      }
>        tg->attrib[i].output_offset = key->element[i].output_offset;
> -
>     }
>  
>     tg->nr_attrib = key->nr_elements;
> 
> _______________________________________________
> mesa-commit mailing list
> mesa-commit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-commit




More information about the mesa-dev mailing list