Skip to content

Commit

Permalink
avutil/file: always set *size to zero if *bufptr is NULL
Browse files Browse the repository at this point in the history
Always set *size to zero if *bufptr is NULL, it's more make sence.

fix #8095

Reviewed-by: Michael Niedermayer <[email protected]>
Signed-off-by: Jun Zhao <[email protected]>
  • Loading branch information
mypopydev committed Aug 30, 2019
1 parent 7c0b3ba commit 7ce15b1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libavutil/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
off_t off_size;
char errbuf[128];
*bufptr = NULL;
*size = 0;

if (fd < 0) {
err = AVERROR(errno);
Expand Down Expand Up @@ -97,6 +98,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
av_strerror(err, errbuf, sizeof(errbuf));
av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in mmap(): %s\n", errbuf);
close(fd);
*size = 0;
return err;
}
*bufptr = ptr;
Expand All @@ -108,6 +110,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
if (!mh) {
av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in CreateFileMapping()\n");
close(fd);
*size = 0;
return -1;
}

Expand All @@ -116,6 +119,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
if (!ptr) {
av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in MapViewOfFile()\n");
close(fd);
*size = 0;
return -1;
}

Expand All @@ -126,6 +130,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
if (!*bufptr) {
av_log(&file_log_ctx, AV_LOG_ERROR, "Memory allocation error occurred\n");
close(fd);
*size = 0;
return AVERROR(ENOMEM);
}
read(fd, *bufptr, *size);
Expand Down

0 comments on commit 7ce15b1

Please sign in to comment.