[Mesa-dev] [PATCH] r600g: Correctly initialize the shader key

Vadim Girlin vadimgirlin at gmail.com
Fri May 3 04:48:31 PDT 2013


On 05/03/2013 03:10 PM, Lauri Kasanen wrote:
> Assigning a struct only copies the members - any padding is left as is.
>
> Thus this code:
>
> struct foo;
> foo = bar;
>
> leaves the padding of foo intact, ie uninitialized random garbage.
>
> This patch fixes constant shader recompiles by initializing the struct
> to zero.
>
> Signed-off-by: Lauri Kasanen <cand at gmx.com>
> ---
>   src/gallium/drivers/r600/r600_state_common.c |    2 +-
>   1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/src/gallium/drivers/r600/r600_state_common.c
> b/src/gallium/drivers/r600/r600_state_common.c index 87a2e2e..bf7cc39
> 100644
> --- a/src/gallium/drivers/r600/r600_state_common.c
> +++ b/src/gallium/drivers/r600/r600_state_common.c
> @@ -710,7 +710,7 @@ static int r600_shader_select(struct pipe_context
> *ctx, struct r600_pipe_shader_selector* sel,
>           bool *dirty)
>   {
> -	struct r600_shader_key key;
> +	struct r600_shader_key key = {0};

I suspect the effect of this initialization on padding is undefined. 
Probably it's safer to use memset.

Vadim

>   	struct r600_context *rctx = (struct r600_context *)ctx;
>   	struct r600_pipe_shader * shader = NULL;
>   	int r;
>



More information about the mesa-dev mailing list