diff mbox series

[FFmpeg-devel,v2] avfilter/f_metadata: use AVBPrint API to remove buf size limitation

Message ID 1591628476-15762-1-git-send-email-lance.lmwang@gmail.com
State New
Headers show
Series [FFmpeg-devel,v2] avfilter/f_metadata: use AVBPrint API to remove buf size limitation
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Limin Wang June 8, 2020, 3:01 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavfilter/f_metadata.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

Comments

Nicolas George June 8, 2020, 3:32 p.m. UTC | #1
lance.lmwang@gmail.com (12020-06-08):
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavfilter/f_metadata.c | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/libavfilter/f_metadata.c b/libavfilter/f_metadata.c
> index 598257b..79515b7 100644
> --- a/libavfilter/f_metadata.c
> +++ b/libavfilter/f_metadata.c
> @@ -31,6 +31,7 @@
>  #include "libavutil/internal.h"
>  #include "libavutil/opt.h"
>  #include "libavutil/timestamp.h"
> +#include "libavutil/bprint.h"
>  #include "libavformat/avio.h"
>  #include "avfilter.h"
>  #include "audio.h"
> @@ -192,14 +193,20 @@ static void print_file(AVFilterContext *ctx, const char *msg, ...)
>  {
>      MetadataContext *s = ctx->priv;
>      va_list argument_list;
> +    AVBPrint buf;
>  
> +    av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
>      va_start(argument_list, msg);
> -    if (msg) {
> -        char buf[128];

> -        vsnprintf(buf, sizeof(buf), msg, argument_list);
> -        avio_write(s->avio_context, buf, av_strnlen(buf, sizeof(buf)));

As pointed in the other mail: this should have been using avio_printf()
from the start.

Error check is still missing, but that's unrelated if it's not in new
code.

> -    }
> +    av_vbprintf(&buf, msg, argument_list);
>      va_end(argument_list);
> +
> +    if (!av_bprint_is_complete(&buf)) {
> +        av_bprint_finalize(&buf, NULL);
> +        av_log(ctx, AV_LOG_ERROR, "No memory for buf\n");
> +        return;
> +    }
> +    avio_write(s->avio_context, buf.str, buf.len);
> +    av_bprint_finalize(&buf, NULL);
>  }
>  
>  static av_cold int init(AVFilterContext *ctx)

Regards,
Limin Wang June 8, 2020, 4:03 p.m. UTC | #2
On Mon, Jun 08, 2020 at 05:32:57PM +0200, Nicolas George wrote:
> lance.lmwang@gmail.com (12020-06-08):
> > From: Limin Wang <lance.lmwang@gmail.com>
> > 
> > Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> > ---
> >  libavfilter/f_metadata.c | 17 ++++++++++++-----
> >  1 file changed, 12 insertions(+), 5 deletions(-)
> > 
> > diff --git a/libavfilter/f_metadata.c b/libavfilter/f_metadata.c
> > index 598257b..79515b7 100644
> > --- a/libavfilter/f_metadata.c
> > +++ b/libavfilter/f_metadata.c
> > @@ -31,6 +31,7 @@
> >  #include "libavutil/internal.h"
> >  #include "libavutil/opt.h"
> >  #include "libavutil/timestamp.h"
> > +#include "libavutil/bprint.h"
> >  #include "libavformat/avio.h"
> >  #include "avfilter.h"
> >  #include "audio.h"
> > @@ -192,14 +193,20 @@ static void print_file(AVFilterContext *ctx, const char *msg, ...)
> >  {
> >      MetadataContext *s = ctx->priv;
> >      va_list argument_list;
> > +    AVBPrint buf;
> >  
> > +    av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
> >      va_start(argument_list, msg);
> > -    if (msg) {
> > -        char buf[128];
> 
> > -        vsnprintf(buf, sizeof(buf), msg, argument_list);
> > -        avio_write(s->avio_context, buf, av_strnlen(buf, sizeof(buf)));
> 
> As pointed in the other mail: this should have been using avio_printf()
> from the start.

I'm trying to use avio_printf() in printf_file(), but the stats result to file isn't expected.
how to use avio_printf()? 

     va_start(argument_list, msg);
     if (msg) {
-        char buf[128];
-        vsnprintf(buf, sizeof(buf), msg, argument_list);
-        avio_write(s->avio_context, buf, av_strnlen(buf, sizeof(buf)));
+        avio_printf(s->avio_context, msg, argument_list);
     }
     va_end(argument_list);
 }


> 
> Error check is still missing, but that's unrelated if it's not in new
> code.
> 
> > -    }
> > +    av_vbprintf(&buf, msg, argument_list);
> >      va_end(argument_list);
> > +
> > +    if (!av_bprint_is_complete(&buf)) {
> > +        av_bprint_finalize(&buf, NULL);
> > +        av_log(ctx, AV_LOG_ERROR, "No memory for buf\n");
> > +        return;
> > +    }
> > +    avio_write(s->avio_context, buf.str, buf.len);
> > +    av_bprint_finalize(&buf, NULL);
> >  }
> >  
> >  static av_cold int init(AVFilterContext *ctx)
> 
> Regards,
> 
> -- 
>   Nicolas George
diff mbox series

Patch

diff --git a/libavfilter/f_metadata.c b/libavfilter/f_metadata.c
index 598257b..79515b7 100644
--- a/libavfilter/f_metadata.c
+++ b/libavfilter/f_metadata.c
@@ -31,6 +31,7 @@ 
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 #include "libavutil/timestamp.h"
+#include "libavutil/bprint.h"
 #include "libavformat/avio.h"
 #include "avfilter.h"
 #include "audio.h"
@@ -192,14 +193,20 @@  static void print_file(AVFilterContext *ctx, const char *msg, ...)
 {
     MetadataContext *s = ctx->priv;
     va_list argument_list;
+    AVBPrint buf;
 
+    av_bprint_init(&buf, 0, AV_BPRINT_SIZE_UNLIMITED);
     va_start(argument_list, msg);
-    if (msg) {
-        char buf[128];
-        vsnprintf(buf, sizeof(buf), msg, argument_list);
-        avio_write(s->avio_context, buf, av_strnlen(buf, sizeof(buf)));
-    }
+    av_vbprintf(&buf, msg, argument_list);
     va_end(argument_list);
+
+    if (!av_bprint_is_complete(&buf)) {
+        av_bprint_finalize(&buf, NULL);
+        av_log(ctx, AV_LOG_ERROR, "No memory for buf\n");
+        return;
+    }
+    avio_write(s->avio_context, buf.str, buf.len);
+    av_bprint_finalize(&buf, NULL);
 }
 
 static av_cold int init(AVFilterContext *ctx)