zink: Check fopen result.
authorVinson Lee <vlee@freedesktop.org>
Wed, 27 May 2020 23:19:25 +0000 (16:19 -0700)
committerMichel Dänzer <michel@daenzer.net>
Fri, 29 May 2020 08:59:19 +0000 (08:59 +0000)
Fix warning reported by Coverity.

Dereference null return value (NULL_RETURNS)
dereference: Dereferencing a pointer that might be NULL fp when calling
fwrite.

Fixes: 8d46e35d16e3 ("zink: introduce opengl over vulkan")
Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5235>

src/gallium/drivers/zink/zink_compiler.c

index 1d9d21df3fee6a477845c69c8aa0587de532a8dc..98ef706fb8fdd0ccc3ef60cec8b438495168834b 100644 (file)
@@ -195,9 +195,11 @@ zink_compile_nir(struct zink_screen *screen, struct nir_shader *nir)
       static int i;
       snprintf(buf, sizeof(buf), "dump%02d.spv", i++);
       FILE *fp = fopen(buf, "wb");
-      fwrite(spirv->words, sizeof(uint32_t), spirv->num_words, fp);
-      fclose(fp);
-      fprintf(stderr, "wrote '%s'...\n", buf);
+      if (fp) {
+         fwrite(spirv->words, sizeof(uint32_t), spirv->num_words, fp);
+         fclose(fp);
+         fprintf(stderr, "wrote '%s'...\n", buf);
+      }
    }
 
    VkShaderModuleCreateInfo smci = {};