Mesa (master): mesa: avoid NULL ptr in prog parameter name

Timothy Arceri tarceri at kemper.freedesktop.org
Wed Apr 12 04:34:26 UTC 2017


Module: Mesa
Branch: master
Commit: 03d1de387ef35c69fb11781b31824f6f2f310006
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=03d1de387ef35c69fb11781b31824f6f2f310006

Author: Gregory Hainaut <gregory.hainaut at gmail.com>
Date:   Tue Apr 11 22:29:17 2017 +0200

mesa: avoid NULL ptr in prog parameter name

Context: _mesa_add_parameter is sometimes[0] called with a
NULL name as a mean of an unnamed parameter.

Allowing NULL pointer as a name means that it must be NULL checked
each access. So far it isn't always[1] true.

Parameter name is only used for debug purpose (printf) and
to lookup the index/location of the program by the application.

Conclusion, there is no valid reason to use a NULL pointer instead of
an empty string. So it was decided to use an empty string which avoid all
issues related to NULL pointer

[0]: texture gather offsets glsl opcode and st_init_atifs_prog
[1]: at least shader cache, st_nir_lookup_parameter_index and some printfs

Issue found by piglit 'texturegatheroffsets' tests on Nouveau

v4: new patch based on Nicolai/Timothy/ilia discussion
Signed-off-by: Gregory Hainaut <gregory.hainaut at gmail.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>

---

 src/mesa/program/prog_parameter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c
index c294b005b8..6689c71f24 100644
--- a/src/mesa/program/prog_parameter.c
+++ b/src/mesa/program/prog_parameter.c
@@ -258,7 +258,7 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
 
    for (i = 0; i < sz4; i++) {
       struct gl_program_parameter *p = paramList->Parameters + oldNum + i;
-      p->Name = name ? strdup(name) : NULL;
+      p->Name = strdup(name ? name : "");
       p->Type = type;
       p->Size = size;
       p->DataType = datatype;




More information about the mesa-commit mailing list