diff mbox series

[FFmpeg-devel] lavfi/drawtext: ignore final LF of textfile.

Message ID 20201130183810.507651-1-george@nsup.org
State New
Headers show
Series [FFmpeg-devel] lavfi/drawtext: ignore final LF of textfile. | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Nicolas George Nov. 30, 2020, 6:38 p.m. UTC
A standard text file ends with a final LF.
Without this change, it is interpreted as an empty final line,
and visible with the box option.
The current behavior can be achieved by actually having
an empty line at the end of the file.

Fix trac ticket #7948.

Signed-off-by: Nicolas George <george@nsup.org>
---
 libavfilter/vf_drawtext.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Gyan Doshi Nov. 30, 2020, 6:40 p.m. UTC | #1
On 01-12-2020 12:08 am, Nicolas George wrote:
> A standard text file ends with a final LF.
> Without this change, it is interpreted as an empty final line,
> and visible with the box option.
> The current behavior can be achieved by actually having
> an empty line at the end of the file.
>
> Fix trac ticket #7948.
>
> Signed-off-by: Nicolas George <george@nsup.org>
> ---
>   libavfilter/vf_drawtext.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
> index abe1ca6c35..0cc47e84a9 100644
> --- a/libavfilter/vf_drawtext.c
> +++ b/libavfilter/vf_drawtext.c
> @@ -583,6 +583,8 @@ static int load_textfile(AVFilterContext *ctx)
>           return err;
>       }
>   
> +    if (textbuf_size > 0 && textbuf[textbuf_size - 1] == '\n')

Isn't it better to use   is_newline()

Regards,
Gyan
Nicolas George Nov. 30, 2020, 6:43 p.m. UTC | #2
Gyan Doshi (12020-12-01):
> Isn't it better to use   is_newline()

Good idea, thanks.

Regards,
Nicolas George Feb. 17, 2021, 11:32 a.m. UTC | #3
Nicolas George (12020-11-30):
> Good idea, thanks.

Pushed.

Regards,
diff mbox series

Patch

diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c
index abe1ca6c35..0cc47e84a9 100644
--- a/libavfilter/vf_drawtext.c
+++ b/libavfilter/vf_drawtext.c
@@ -583,6 +583,8 @@  static int load_textfile(AVFilterContext *ctx)
         return err;
     }
 
+    if (textbuf_size > 0 && textbuf[textbuf_size - 1] == '\n')
+        textbuf_size--;
     if (textbuf_size > SIZE_MAX - 1 || !(tmp = av_realloc(s->text, textbuf_size + 1))) {
         av_file_unmap(textbuf, textbuf_size);
         return AVERROR(ENOMEM);