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

Alex Deucher alexdeucher at gmail.com
Fri May 3 07:54:09 PDT 2013


On Fri, May 3, 2013 at 9:55 AM, Lauri Kasanen <cand at gmx.com> wrote:
> Assigning a struct only copies the members - any padding is left as is.
>
> Thus this code:
>
> struct foo_t 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. For completeness, memcpy is used to copy the key to the shader
> struct.
>

Candidate for the stable branch?

Alex

> Signed-off-by: Lauri Kasanen <cand at gmx.com>
> ---
>  src/gallium/drivers/r600/r600_state_common.c |    3 ++-
>  1 files changed, 2 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..fbac576
> 100644
> --- a/src/gallium/drivers/r600/r600_state_common.c
> +++ b/src/gallium/drivers/r600/r600_state_common.c
> @@ -715,6 +715,7 @@ static int r600_shader_select(struct pipe_context
> *ctx, struct r600_pipe_shader * shader = NULL;
>         int r;
>
> +       memset(&key, 0, sizeof(key));
>         key = r600_shader_selector_key(ctx, sel);
>
>         /* Check if we don't need to change anything.
> @@ -762,7 +763,7 @@ static int r600_shader_select(struct pipe_context
> *ctx, key = r600_shader_selector_key(ctx, sel);
>                 }
>
> -               shader->key = key;
> +               memcpy(&shader->key, &key, sizeof(key));
>                 sel->num_shaders++;
>         }
>
> --
> 1.7.2.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list