[Mesa-dev] [PATCH 1/2] i965: NULL check prog on compilation failure.

Matt Turner mattst88 at gmail.com
Tue Apr 9 13:31:39 PDT 2013


I believe that prog can only be NULL for ARB programs. Neither
brw_fs_fp.cpp nor brw_vec4_vp.cpp call fail(), but not NULL checking
prog is obviously fragile.
---
 src/mesa/drivers/dri/i965/brw_fs.cpp   | 8 +++++---
 src/mesa/drivers/dri/i965/brw_vec4.cpp | 8 +++++---
 src/mesa/drivers/dri/i965/brw_vs.c     | 2 +-
 src/mesa/drivers/dri/i965/brw_wm.c     | 2 +-
 4 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index c12ba45..2086af8 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -2886,7 +2886,7 @@ brw_wm_fs_emit(struct brw_context *brw, struct brw_wm_compile *c,
 
    if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
       if (shader) {
-         printf("GLSL IR for native fragment shader %d:\n", prog->Name);
+         printf("GLSL IR for native fragment shader %d:\n", prog ? prog->Name : -1);
          _mesa_print_ir(shader->ir, NULL);
          printf("\n\n");
       } else {
@@ -2900,8 +2900,10 @@ brw_wm_fs_emit(struct brw_context *brw, struct brw_wm_compile *c,
     */
    fs_visitor v(brw, c, prog, fp, 8);
    if (!v.run()) {
-      prog->LinkStatus = false;
-      ralloc_strcat(&prog->InfoLog, v.fail_msg);
+      if (prog) {
+         prog->LinkStatus = false;
+         ralloc_strcat(&prog->InfoLog, v.fail_msg);
+      }
 
       _mesa_problem(NULL, "Failed to compile fragment shader: %s\n",
 		    v.fail_msg);
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp
index c58fb44..446b4cf 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp
@@ -1506,7 +1506,7 @@ brw_vs_emit(struct brw_context *brw,
 
    if (unlikely(INTEL_DEBUG & DEBUG_VS)) {
       if (shader) {
-         printf("GLSL IR for native vertex shader %d:\n", prog->Name);
+         printf("GLSL IR for native vertex shader %d:\n", prog ? prog->Name : -1);
          _mesa_print_ir(shader->ir, NULL);
          printf("\n\n");
       } else {
@@ -1518,8 +1518,10 @@ brw_vs_emit(struct brw_context *brw,
 
    vec4_visitor v(brw, c, prog, shader, mem_ctx);
    if (!v.run()) {
-      prog->LinkStatus = false;
-      ralloc_strcat(&prog->InfoLog, v.fail_msg);
+      if (prog) {
+         prog->LinkStatus = false;
+         ralloc_strcat(&prog->InfoLog, v.fail_msg);
+      }
       return NULL;
    }
 
diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c
index 6d2c0fd..f7a5e41 100644
--- a/src/mesa/drivers/dri/i965/brw_vs.c
+++ b/src/mesa/drivers/dri/i965/brw_vs.c
@@ -351,7 +351,7 @@ brw_vs_debug_recompile(struct brw_context *brw,
    const struct brw_vs_prog_key *old_key = NULL;
    bool found = false;
 
-   perf_debug("Recompiling vertex shader for program %d\n", prog->Name);
+   perf_debug("Recompiling vertex shader for program %d\n", prog ? prog->Name : -1);
 
    for (unsigned int i = 0; i < brw->cache.size; i++) {
       for (c = brw->cache.items[i]; c; c = c->next) {
diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
index 9b30ba1..6bd95b4 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -248,7 +248,7 @@ brw_wm_debug_recompile(struct brw_context *brw,
    const struct brw_wm_prog_key *old_key = NULL;
    bool found = false;
 
-   perf_debug("Recompiling fragment shader for program %d\n", prog->Name);
+   perf_debug("Recompiling fragment shader for program %d\n", prog ? prog->Name : -1);
 
    for (unsigned int i = 0; i < brw->cache.size; i++) {
       for (c = brw->cache.items[i]; c; c = c->next) {
-- 
1.8.1.5



More information about the mesa-dev mailing list