Commit 7ce15b1d authored by Jun Zhao's avatar Jun Zhao

avutil/file: always set *size to zero if *bufptr is NULL

Always set *size to zero if *bufptr is NULL, it's more make sence.

fix #8095
Reviewed-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
Signed-off-by: 's avatarJun Zhao <barryjzhao@tencent.com>
parent 7c0b3ba7
...@@ -60,6 +60,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, ...@@ -60,6 +60,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
off_t off_size; off_t off_size;
char errbuf[128]; char errbuf[128];
*bufptr = NULL; *bufptr = NULL;
*size = 0;
if (fd < 0) { if (fd < 0) {
err = AVERROR(errno); err = AVERROR(errno);
...@@ -97,6 +98,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, ...@@ -97,6 +98,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
av_strerror(err, errbuf, sizeof(errbuf)); av_strerror(err, errbuf, sizeof(errbuf));
av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in mmap(): %s\n", errbuf); av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in mmap(): %s\n", errbuf);
close(fd); close(fd);
*size = 0;
return err; return err;
} }
*bufptr = ptr; *bufptr = ptr;
...@@ -108,6 +110,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, ...@@ -108,6 +110,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
if (!mh) { if (!mh) {
av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in CreateFileMapping()\n"); av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in CreateFileMapping()\n");
close(fd); close(fd);
*size = 0;
return -1; return -1;
} }
...@@ -116,6 +119,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, ...@@ -116,6 +119,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
if (!ptr) { if (!ptr) {
av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in MapViewOfFile()\n"); av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in MapViewOfFile()\n");
close(fd); close(fd);
*size = 0;
return -1; return -1;
} }
...@@ -126,6 +130,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size, ...@@ -126,6 +130,7 @@ int av_file_map(const char *filename, uint8_t **bufptr, size_t *size,
if (!*bufptr) { if (!*bufptr) {
av_log(&file_log_ctx, AV_LOG_ERROR, "Memory allocation error occurred\n"); av_log(&file_log_ctx, AV_LOG_ERROR, "Memory allocation error occurred\n");
close(fd); close(fd);
*size = 0;
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
read(fd, *bufptr, *size); read(fd, *bufptr, *size);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment