[FFmpeg-devel,V1] avutil/file: always set *size to zero if *bufptr is NULL

Submitted by Jun Zhao on Aug. 28, 2019, 5:04 p.m.

Details

Message ID 1567011883-32302-1-git-send-email-mypopydev@gmail.com
State New
Headers show

Commit Message

Jun Zhao Aug. 28, 2019, 5:04 p.m.
From: Jun Zhao <barryjzhao@tencent.com>

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

fix #8095

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
---
 libavutil/file.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

Comments

Michael Niedermayer Aug. 29, 2019, 1:07 p.m.
On Thu, Aug 29, 2019 at 01:04:43AM +0800, Jun Zhao wrote:
> From: Jun Zhao <barryjzhao@tencent.com>
> 
> Always set *size to zero if *bufptr is NULL, it's more make sence.
> 
> fix #8095
> 
> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> ---
>  libavutil/file.c |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)

probably ok

maybe the av_file_unmap and av_file_map changes could be in seperate patches

thx

[...]
mypopy@gmail.com Aug. 30, 2019, 1:04 a.m.
On Thu, Aug 29, 2019 at 9:07 PM Michael Niedermayer
<michael@niedermayer.cc> wrote:
>
> On Thu, Aug 29, 2019 at 01:04:43AM +0800, Jun Zhao wrote:
> > From: Jun Zhao <barryjzhao@tencent.com>
> >
> > Always set *size to zero if *bufptr is NULL, it's more make sence.
> >
> > fix #8095
> >
> > Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
> > ---
> >  libavutil/file.c |    7 ++++++-
> >  1 files changed, 6 insertions(+), 1 deletions(-)
>
> probably ok
>
> maybe the av_file_unmap and av_file_map changes could be in seperate patches
>
> thx
>
> [...]
Thanks, will split the patch
Paul B Mahol Aug. 30, 2019, 6:50 a.m.
On 8/30/19, mypopy@gmail.com <mypopy@gmail.com> wrote:
> On Thu, Aug 29, 2019 at 9:07 PM Michael Niedermayer
> <michael@niedermayer.cc> wrote:
>>
>> On Thu, Aug 29, 2019 at 01:04:43AM +0800, Jun Zhao wrote:
>> > From: Jun Zhao <barryjzhao@tencent.com>
>> >
>> > Always set *size to zero if *bufptr is NULL, it's more make sence.
>> >
>> > fix #8095
>> >
>> > Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
>> > ---
>> >  libavutil/file.c |    7 ++++++-
>> >  1 files changed, 6 insertions(+), 1 deletions(-)
>>
>> probably ok
>>
>> maybe the av_file_unmap and av_file_map changes could be in seperate
>> patches
>>
>> thx
>>
>> [...]
> Thanks, will split the patch

Please refrain from applying patches that have typos in logs.

Patch hide | download patch | download mbox

diff --git a/libavutil/file.c b/libavutil/file.c
index d946085..f228b72 100644
--- a/libavutil/file.c
+++ b/libavutil/file.c
@@ -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);
@@ -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;
@@ -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;
         }
 
@@ -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;
         }
 
@@ -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);
@@ -138,7 +143,7 @@  out:
 
 void av_file_unmap(uint8_t *bufptr, size_t size)
 {
-    if (!size)
+    if (!size || !bufptr)
         return;
 #if HAVE_MMAP
     munmap(bufptr, size);