diff options
author | Marton Balint <cus@passwd.hu> | 2018-09-06 21:46:16 +0300 |
---|---|---|
committer | Marton Balint <cus@passwd.hu> | 2018-09-09 22:21:42 +0300 |
commit | 4737387d288d1e87e7c7df6203a42d6b1e88231e (patch) | |
tree | 69e773b38dc8136d3650947244b873321e679eca /libavutil/file.c | |
parent | bd3c27fd7aa35ab3c0de03ffff598840634c7c2f (diff) |
avutil/file: allow mapping 0 byte files with av_file_map
Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavutil/file.c')
-rw-r--r-- | libavutil/file.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libavutil/file.c b/libavutil/file.c index 24a86c3f35..d946085b28 100644 --- a/libavutil/file.c +++ b/libavutil/file.c @@ -85,6 +85,11 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, } *size = off_size; + if (!*size) { + *bufptr = NULL; + goto out; + } + #if HAVE_MMAP ptr = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); if (ptr == MAP_FAILED) { @@ -126,12 +131,15 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, read(fd, *bufptr, *size); #endif +out: close(fd); return 0; } void av_file_unmap(uint8_t *bufptr, size_t size) { + if (!size) + return; #if HAVE_MMAP munmap(bufptr, size); #elif HAVE_MAPVIEWOFFILE |