[Mesa-dev] [PATCH] nir: Check if u_vector_init() succeeds

Thomas Helland thomashelland90 at gmail.com
Thu Apr 5 08:50:54 UTC 2018


Sorry about that. It doesn't hurt to check.

Reviewed-by: Thomas Helland <thomashelland90 at gmail.com>

2018-04-05 9:35 GMT+02:00 Topi Pohjolainen <topi.pohjolainen at gmail.com>:
> However, it only fails when running out of memory. Now, if we
> are about to check that, we should be consistent and check
> the allocation of the worklist as well.
>
> On the other hand there are other places where we don't check
> for allocation failures. Therefore I'm not sure if we bother
> here either. Coverity complains but I can mark it as ignored
> the same.
>
> CID: 1433512
> Fixes: edb18564c7 nir: Initial implementation of a nir_instr_worklist
> CC: Thomas Helland <thomashelland90 at gmail.com>
> Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
> ---
>  src/compiler/nir/nir_worklist.h | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/src/compiler/nir/nir_worklist.h b/src/compiler/nir/nir_worklist.h
> index e376908..3fb391f 100644
> --- a/src/compiler/nir/nir_worklist.h
> +++ b/src/compiler/nir/nir_worklist.h
> @@ -105,8 +105,15 @@ typedef struct {
>  static inline nir_instr_worklist *
>  nir_instr_worklist_create() {
>     nir_instr_worklist *wl = malloc(sizeof(nir_instr_worklist));
> -   u_vector_init(&wl->instr_vec, sizeof(struct nir_instr *),
> -                 sizeof(struct nir_instr *) * 8);
> +   if (!wl)
> +      return NULL;
> +
> +   if (!u_vector_init(&wl->instr_vec, sizeof(struct nir_instr *),
> +                      sizeof(struct nir_instr *) * 8)) {
> +      free(wl);
> +      return NULL;
> +   }
> +
>     return wl;
>  }
>
> --
> 2.7.4
>


More information about the mesa-dev mailing list