[Mesa-dev] [PATCH] st/mesa: init hash keys with memset(), not designated initializers

Neha Bhende bhenden at vmware.com
Fri Mar 8 19:24:39 UTC 2019


Reviewed-by: Neha Bhende <bhenden at vmware.com>

Regards,
Neha

________________________________________
From: mesa-dev <mesa-dev-bounces at lists.freedesktop.org> on behalf of Brian Paul <brianp at vmware.com>
Sent: Friday, March 8, 2019 9:14 AM
To: mesa-dev at lists.freedesktop.org
Cc: Neha Bhende
Subject: [Mesa-dev] [PATCH] st/mesa: init hash keys with memset(), not designated initializers

Since the compiler may not zero-out padding in the object.
Add a couple comments about this to prevent misunderstandings in
the future.

Fixes: 67d96816ff5 ("st/mesa: move, clean-up shader variant key decls/inits")
---
 src/mesa/state_tracker/st_atom_shader.c |  9 +++++++--
 src/mesa/state_tracker/st_program.c     | 13 ++++++++++---
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c
index ac7a1a5..a4475e2 100644
--- a/src/mesa/state_tracker/st_atom_shader.c
+++ b/src/mesa/state_tracker/st_atom_shader.c
@@ -112,7 +112,10 @@ st_update_fp( struct st_context *st )
        !stfp->variants->key.bitmap) {
       shader = stfp->variants->driver_shader;
    } else {
-      struct st_fp_variant_key key = {0};
+      struct st_fp_variant_key key;
+
+      /* use memset, not an initializer to be sure all memory is zeroed */
+      memset(&key, 0, sizeof(key));

       key.st = st->has_shareable_shaders ? NULL : st;

@@ -168,7 +171,9 @@ st_update_vp( struct st_context *st )
        stvp->variants->key.passthrough_edgeflags == st->vertdata_edgeflags) {
       st->vp_variant = stvp->variants;
    } else {
-      struct st_vp_variant_key key = {0};
+      struct st_vp_variant_key key;
+
+      memset(&key, 0, sizeof(key));

       key.st = st->has_shareable_shaders ? NULL : st;

diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index 6d669a9..fe03070 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -1807,7 +1807,10 @@ st_get_cp_variant(struct st_context *st,
 {
    struct pipe_context *pipe = st->pipe;
    struct st_basic_variant *v;
-   struct st_basic_variant_key key = {0};
+   struct st_basic_variant_key key;
+
+   /* use memset, not an initializer to be sure all memory is zeroed */
+   memset(&key, 0, sizeof(key));

    key.st = st->has_shareable_shaders ? NULL : st;

@@ -2030,7 +2033,9 @@ st_precompile_shader_variant(struct st_context *st,
    switch (prog->Target) {
    case GL_VERTEX_PROGRAM_ARB: {
       struct st_vertex_program *p = (struct st_vertex_program *)prog;
-      struct st_vp_variant_key key = {0};
+      struct st_vp_variant_key key;
+
+      memset(&key, 0, sizeof(key));

       key.st = st->has_shareable_shaders ? NULL : st;
       st_get_vp_variant(st, p, &key);
@@ -2057,7 +2062,9 @@ st_precompile_shader_variant(struct st_context *st,

    case GL_FRAGMENT_PROGRAM_ARB: {
       struct st_fragment_program *p = (struct st_fragment_program *)prog;
-      struct st_fp_variant_key key = {0};
+      struct st_fp_variant_key key;
+
+      memset(&key, 0, sizeof(key));

       key.st = st->has_shareable_shaders ? NULL : st;
       st_get_fp_variant(st, p, &key);
--
1.8.5.6

_______________________________________________
mesa-dev mailing list
mesa-dev at lists.freedesktop.org
https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fmesa-dev&data=02%7C01%7Cbhenden%40vmware.com%7C773d52000a58466ac0d508d6a3e98df6%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636876620836813700&sdata=pyvSVyPLzF8JXaiMptIRwvddQX2Hh7rm%2FAV%2BivL%2FOOE%3D&reserved=0


More information about the mesa-dev mailing list