summaryrefslogtreecommitdiffstats
path: root/src/compiler/spirv
diff options
context:
space:
mode:
authorEric Engestrom <eric@engestrom.ch>2016-09-25 16:49:51 +0100
committerJason Ekstrand <jason.ekstrand@intel.com>2016-10-01 15:27:44 -0700
commit65c8cbe89df3c0e23e83f32111cce6609f86c85d (patch)
tree70b2c41c0e009787ecd6276c9158d28f16eb0890 /src/compiler/spirv
parent23519a9de259c5f8c837421330c9a05912b4e8e6 (diff)
downloadexternal_mesa3d-65c8cbe89df3c0e23e83f32111cce6609f86c85d.zip
external_mesa3d-65c8cbe89df3c0e23e83f32111cce6609f86c85d.tar.gz
external_mesa3d-65c8cbe89df3c0e23e83f32111cce6609f86c85d.tar.bz2
nir/spirv: improve lseek() error handling
Signed-off-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Diffstat (limited to 'src/compiler/spirv')
-rw-r--r--src/compiler/spirv/spirv2nir.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/compiler/spirv/spirv2nir.c b/src/compiler/spirv/spirv2nir.c
index d151c2c..a024028 100644
--- a/src/compiler/spirv/spirv2nir.c
+++ b/src/compiler/spirv/spirv2nir.c
@@ -39,6 +39,8 @@
#include <unistd.h>
#include <stdio.h>
+#define WORD_SIZE 4
+
int main(int argc, char **argv)
{
int fd = open(argv[1], O_RDONLY);
@@ -49,9 +51,15 @@ int main(int argc, char **argv)
}
off_t len = lseek(fd, 0, SEEK_END);
+ if (len % WORD_SIZE != 0)
+ {
+ fprintf(stderr, "File length isn't a multiple of the word size\n");
+ fprintf(stderr, "Are you sure this is a valid SPIR-V shader?\n");
+ close(fd);
+ return 1;
+ }
- assert(len % 4 == 0);
- size_t word_count = len / 4;
+ size_t word_count = len / WORD_SIZE;
const void *map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
assert(map != NULL);