[Mesa-dev] [PATCH 10/11] glsl: Add null check in loop_analysis.cpp

Ian Romanick idr at freedesktop.org
Fri Apr 4 13:41:06 PDT 2014


On 04/04/2014 03:28 AM, Juha-Pekka Heikkila wrote:
> Check return value from hash_table_find before using it as a pointer
> 
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
>  src/glsl/loop_analysis.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/glsl/loop_analysis.cpp b/src/glsl/loop_analysis.cpp
> index d6a9ac7..5e4eaa1 100644
> --- a/src/glsl/loop_analysis.cpp
> +++ b/src/glsl/loop_analysis.cpp
> @@ -589,7 +589,7 @@ get_basic_induction_increment(ir_assignment *ir, hash_table *var_hash)
>  	 loop_variable *lv =
>  	    (loop_variable *) hash_table_find(var_hash, inc_var);
>  
> -	 if (!lv->is_loop_constant())
> +      if (lv == NULL || !lv->is_loop_constant())

I think this case is more catastrophic than that.  This means we've
encountered a variable inside a loop, but that variable isn't in the
table of variables used inside the loop.  Just putting a NULL check here
will make it more difficult to find a real bug, should one exist.

I think I'd also want an assert(lv != NULL) inside the if block.

>  	    inc = NULL;
>        } else
>  	 inc = NULL;



More information about the mesa-dev mailing list