nir/spirv: improve mmap() error handling
authorEric Engestrom <eric@engestrom.ch>
Sun, 25 Sep 2016 15:49:52 +0000 (16:49 +0100)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sat, 1 Oct 2016 22:27:46 +0000 (15:27 -0700)
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/spirv/spirv2nir.c

index a02402874fc3a011a397724807e6c798bcea0901..3dc073513221a834beaf33c818687fd70ec5dc6c 100644 (file)
@@ -38,6 +38,8 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <errno.h>
+#include <string.h>
 
 #define WORD_SIZE 4
 
@@ -62,7 +64,13 @@ int main(int argc, char **argv)
    size_t word_count = len / WORD_SIZE;
 
    const void *map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
-   assert(map != NULL);
+   if (map == MAP_FAILED)
+   {
+      fprintf(stderr, "Failed to mmap the file: errno=%d, %s\n",
+              errno, strerror(errno));
+      close(fd);
+      return 1;
+   }
 
    nir_function *func = spirv_to_nir(map, word_count, NULL, 0,
                                      MESA_SHADER_FRAGMENT, "main", NULL);