Re: [FFmpeg-devel] [PATCH] lavf/aviobuf: add ff_get_line2() variant

2016-10-20 Thread Michael Niedermayer
On Thu, Oct 20, 2016 at 04:05:07PM +0200, Stefano Sabatini wrote:
> On date Tuesday 2016-10-18 16:48:02 +0200, Michael Niedermayer encoded:
> > On Tue, Oct 18, 2016 at 01:32:12PM +0200, Stefano Sabatini wrote:
> [...]
> > >  aviobuf.c  |   18 +++---
> > >  internal.h |   14 ++
> > >  2 files changed, 29 insertions(+), 3 deletions(-)
> > > 19b979c45f087997ac69fba2caf5504c933acfc8  
> > > 0001-lavf-aviobuf-add-ff_get_line2-variant.patch
> > > From 58c1cad434447d48246e153e3a1a391d72d23c7b Mon Sep 17 00:00:00 2001
> > > From: Stefano Sabatini 
> > > Date: Thu, 13 Oct 2016 16:36:30 +0200
> > > Subject: [PATCH] lavf/aviobuf: add ff_get_line2() variant
> > > 
> > > This allows to probe if the read line was partially discarded.
> > > ---
> > >  libavformat/aviobuf.c  | 18 +++---
> > >  libavformat/internal.h | 14 ++
> > >  2 files changed, 29 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> > > index 134d627..29bcf1e 100644
> > > --- a/libavformat/aviobuf.c
> > > +++ b/libavformat/aviobuf.c
> > > @@ -764,18 +764,30 @@ unsigned int avio_rb32(AVIOContext *s)
> > >  
> > >  int ff_get_line(AVIOContext *s, char *buf, int maxlen)
> > >  {
> > > -int i = 0;
> > > +return ff_get_line2(s, buf, maxlen, NULL);
> > > +}
> > > +
> > > +int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen)
> > > +{
> > > +int i = 0, j = 0;
> > >  char c;
> > >  
> > > +while (1) {
> > >  c = avio_r8(s);
> > >  if (c && i < maxlen-1)
> > >  buf[i++] = c;
> > > +if (c != '\n' && c != '\r' && c) {
> > > +j++;
> > > +} else {
> > > +break;
> > > +}
> > > +}
> > 
> > a string like "\n"
> > would have a strlen of 1
> > but readlen of 0
> > while a string like "X" would have a strlen and readlen of 1
> > 
> > is this difference intended ?
> > or maybe i misread the code
> 
> You're right, I was confused.
> 
> Updated patch in attachment, thanks.
> -- 
> FFmpeg = Frightening and Fierce Moronic Power Elected Geisha

>  aviobuf.c  |   16 +---
>  internal.h |   14 ++
>  2 files changed, 27 insertions(+), 3 deletions(-)
> ff84236587ab1ebec44e4b835a734757c59fd614  
> 0001-lavf-aviobuf-add-ff_get_line2-variant.patch
> From 54a5d3469d4d9a3f17f45e7577da6c46cb7e969e Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini 
> Date: Thu, 13 Oct 2016 16:36:30 +0200
> Subject: [PATCH] lavf/aviobuf: add ff_get_line2() variant
> 
> This allows to probe if the read line was partially discarded.
> ---
>  libavformat/aviobuf.c  | 16 +---
>  libavformat/internal.h | 14 ++
>  2 files changed, 27 insertions(+), 3 deletions(-)

LGTM

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If you fake or manipulate statistics in a paper in physics you will never
get a job again.
If you fake or manipulate statistics in a paper in medicin you will get
a job for life at the pharma industry.


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/aviobuf: add ff_get_line2() variant

2016-10-20 Thread Stefano Sabatini
On date Tuesday 2016-10-18 16:48:02 +0200, Michael Niedermayer encoded:
> On Tue, Oct 18, 2016 at 01:32:12PM +0200, Stefano Sabatini wrote:
[...]
> >  aviobuf.c  |   18 +++---
> >  internal.h |   14 ++
> >  2 files changed, 29 insertions(+), 3 deletions(-)
> > 19b979c45f087997ac69fba2caf5504c933acfc8  
> > 0001-lavf-aviobuf-add-ff_get_line2-variant.patch
> > From 58c1cad434447d48246e153e3a1a391d72d23c7b Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini 
> > Date: Thu, 13 Oct 2016 16:36:30 +0200
> > Subject: [PATCH] lavf/aviobuf: add ff_get_line2() variant
> > 
> > This allows to probe if the read line was partially discarded.
> > ---
> >  libavformat/aviobuf.c  | 18 +++---
> >  libavformat/internal.h | 14 ++
> >  2 files changed, 29 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> > index 134d627..29bcf1e 100644
> > --- a/libavformat/aviobuf.c
> > +++ b/libavformat/aviobuf.c
> > @@ -764,18 +764,30 @@ unsigned int avio_rb32(AVIOContext *s)
> >  
> >  int ff_get_line(AVIOContext *s, char *buf, int maxlen)
> >  {
> > -int i = 0;
> > +return ff_get_line2(s, buf, maxlen, NULL);
> > +}
> > +
> > +int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen)
> > +{
> > +int i = 0, j = 0;
> >  char c;
> >  
> > +while (1) {
> >  c = avio_r8(s);
> >  if (c && i < maxlen-1)
> >  buf[i++] = c;
> > +if (c != '\n' && c != '\r' && c) {
> > +j++;
> > +} else {
> > +break;
> > +}
> > +}
> 
> a string like "\n"
> would have a strlen of 1
> but readlen of 0
> while a string like "X" would have a strlen and readlen of 1
> 
> is this difference intended ?
> or maybe i misread the code

You're right, I was confused.

Updated patch in attachment, thanks.
-- 
FFmpeg = Frightening and Fierce Moronic Power Elected Geisha
>From 54a5d3469d4d9a3f17f45e7577da6c46cb7e969e Mon Sep 17 00:00:00 2001
From: Stefano Sabatini 
Date: Thu, 13 Oct 2016 16:36:30 +0200
Subject: [PATCH] lavf/aviobuf: add ff_get_line2() variant

This allows to probe if the read line was partially discarded.
---
 libavformat/aviobuf.c  | 16 +---
 libavformat/internal.h | 14 ++
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 134d627..144a617 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -764,18 +764,28 @@ unsigned int avio_rb32(AVIOContext *s)
 
 int ff_get_line(AVIOContext *s, char *buf, int maxlen)
 {
-int i = 0;
+return ff_get_line2(s, buf, maxlen, NULL);
+}
+
+int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen)
+{
+int i = 0, j = 0;
 char c;
 
 do {
 c = avio_r8(s);
-if (c && i < maxlen-1)
-buf[i++] = c;
+if (c) {
+if (i < maxlen-1)
+buf[i++] = c;
+j++;
+}
 } while (c != '\n' && c != '\r' && c);
 if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
 avio_skip(s, -1);
 
 buf[i] = 0;
+if (readlen)
+*readlen = j;
 return i;
 }
 
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 49244fa..fc49571 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -274,6 +274,20 @@ void ff_put_v(AVIOContext *bc, uint64_t val);
  */
 int ff_get_line(AVIOContext *s, char *buf, int maxlen);
 
+/**
+ * Read a whole line of text from AVIOContext. Stop reading after reaching
+ * either a \\n, a \\0 or EOF. The returned string is always \\0-terminated,
+ * and may be truncated if the buffer is too small.
+ *
+ * @param s the read-only AVIOContext
+ * @param buf buffer to store the read line
+ * @param maxlen size of the buffer
+ * @param readlen length of the read line, not including the final \\0
+ * @return the length of the string written in the buffer, not including the
+ * final \\0
+ */
+int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen);
+
 #define SPACE_CHARS " \t\r\n"
 
 /**
-- 
1.9.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/aviobuf: add ff_get_line2() variant

2016-10-18 Thread Michael Niedermayer
On Tue, Oct 18, 2016 at 01:32:12PM +0200, Stefano Sabatini wrote:
> On date Thursday 2016-10-13 21:59:19 +0200, Michael Niedermayer encoded:
> > On Thu, Oct 13, 2016 at 07:40:59PM +0200, Stefano Sabatini wrote:
> > > This allows to probe if the read line was partially discarded.
> > > ---
> > >  libavformat/aviobuf.c  | 10 +-
> > >  libavformat/internal.h | 14 ++
> > >  2 files changed, 23 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> > > index 134d627..28183b4 100644
> > > --- a/libavformat/aviobuf.c
> > > +++ b/libavformat/aviobuf.c
> > > @@ -764,18 +764,26 @@ unsigned int avio_rb32(AVIOContext *s)
> > >  
> > >  int ff_get_line(AVIOContext *s, char *buf, int maxlen)
> > >  {
> > > -int i = 0;
> > > +return ff_get_line2(s, buf, maxlen, NULL);
> > > +}
> > > +
> > > +int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen)
> > > +{
> > > +int i = 0, j = 0;
> > >  char c;
> > >  
> > >  do {
> > >  c = avio_r8(s);
> > >  if (c && i < maxlen-1)
> > >  buf[i++] = c;
> > > +j++;
> > >  } while (c != '\n' && c != '\r' && c);
> > 
> 
> > "\n" and "\0" would i belive both have a j=1 but they would have
> > differig i
> > is that intended ? (seems to me that this would make truncation
> > detection more annoying)
> > or am i missing something that avoids this difference?
> 
> Improved version in attachment.
> -- 
> FFmpeg = Fascinating Foolish Mystic Puritan Egregious Gymnast

>  aviobuf.c  |   18 +++---
>  internal.h |   14 ++
>  2 files changed, 29 insertions(+), 3 deletions(-)
> 19b979c45f087997ac69fba2caf5504c933acfc8  
> 0001-lavf-aviobuf-add-ff_get_line2-variant.patch
> From 58c1cad434447d48246e153e3a1a391d72d23c7b Mon Sep 17 00:00:00 2001
> From: Stefano Sabatini 
> Date: Thu, 13 Oct 2016 16:36:30 +0200
> Subject: [PATCH] lavf/aviobuf: add ff_get_line2() variant
> 
> This allows to probe if the read line was partially discarded.
> ---
>  libavformat/aviobuf.c  | 18 +++---
>  libavformat/internal.h | 14 ++
>  2 files changed, 29 insertions(+), 3 deletions(-)
> 
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index 134d627..29bcf1e 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -764,18 +764,30 @@ unsigned int avio_rb32(AVIOContext *s)
>  
>  int ff_get_line(AVIOContext *s, char *buf, int maxlen)
>  {
> -int i = 0;
> +return ff_get_line2(s, buf, maxlen, NULL);
> +}
> +
> +int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen)
> +{
> +int i = 0, j = 0;
>  char c;
>  
> +while (1) {
>  c = avio_r8(s);
>  if (c && i < maxlen-1)
>  buf[i++] = c;
> +if (c != '\n' && c != '\r' && c) {
> +j++;
> +} else {
> +break;
> +}
> +}

a string like "\n"
would have a strlen of 1
but readlen of 0
while a string like "X" would have a strlen and readlen of 1

is this difference intended ?
or maybe i misread the code

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato 


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/aviobuf: add ff_get_line2() variant

2016-10-18 Thread Stefano Sabatini
On date Thursday 2016-10-13 21:59:19 +0200, Michael Niedermayer encoded:
> On Thu, Oct 13, 2016 at 07:40:59PM +0200, Stefano Sabatini wrote:
> > This allows to probe if the read line was partially discarded.
> > ---
> >  libavformat/aviobuf.c  | 10 +-
> >  libavformat/internal.h | 14 ++
> >  2 files changed, 23 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> > index 134d627..28183b4 100644
> > --- a/libavformat/aviobuf.c
> > +++ b/libavformat/aviobuf.c
> > @@ -764,18 +764,26 @@ unsigned int avio_rb32(AVIOContext *s)
> >  
> >  int ff_get_line(AVIOContext *s, char *buf, int maxlen)
> >  {
> > -int i = 0;
> > +return ff_get_line2(s, buf, maxlen, NULL);
> > +}
> > +
> > +int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen)
> > +{
> > +int i = 0, j = 0;
> >  char c;
> >  
> >  do {
> >  c = avio_r8(s);
> >  if (c && i < maxlen-1)
> >  buf[i++] = c;
> > +j++;
> >  } while (c != '\n' && c != '\r' && c);
> 

> "\n" and "\0" would i belive both have a j=1 but they would have
> differig i
> is that intended ? (seems to me that this would make truncation
> detection more annoying)
> or am i missing something that avoids this difference?

Improved version in attachment.
-- 
FFmpeg = Fascinating Foolish Mystic Puritan Egregious Gymnast
>From 58c1cad434447d48246e153e3a1a391d72d23c7b Mon Sep 17 00:00:00 2001
From: Stefano Sabatini 
Date: Thu, 13 Oct 2016 16:36:30 +0200
Subject: [PATCH] lavf/aviobuf: add ff_get_line2() variant

This allows to probe if the read line was partially discarded.
---
 libavformat/aviobuf.c  | 18 +++---
 libavformat/internal.h | 14 ++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 134d627..29bcf1e 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -764,18 +764,30 @@ unsigned int avio_rb32(AVIOContext *s)
 
 int ff_get_line(AVIOContext *s, char *buf, int maxlen)
 {
-int i = 0;
+return ff_get_line2(s, buf, maxlen, NULL);
+}
+
+int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen)
+{
+int i = 0, j = 0;
 char c;
 
-do {
+while (1) {
 c = avio_r8(s);
 if (c && i < maxlen-1)
 buf[i++] = c;
-} while (c != '\n' && c != '\r' && c);
+if (c != '\n' && c != '\r' && c) {
+j++;
+} else {
+break;
+}
+}
 if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
 avio_skip(s, -1);
 
 buf[i] = 0;
+if (readlen)
+*readlen = j;
 return i;
 }
 
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 49244fa..fc49571 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -274,6 +274,20 @@ void ff_put_v(AVIOContext *bc, uint64_t val);
  */
 int ff_get_line(AVIOContext *s, char *buf, int maxlen);
 
+/**
+ * Read a whole line of text from AVIOContext. Stop reading after reaching
+ * either a \\n, a \\0 or EOF. The returned string is always \\0-terminated,
+ * and may be truncated if the buffer is too small.
+ *
+ * @param s the read-only AVIOContext
+ * @param buf buffer to store the read line
+ * @param maxlen size of the buffer
+ * @param readlen length of the read line, not including the final \\0
+ * @return the length of the string written in the buffer, not including the
+ * final \\0
+ */
+int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen);
+
 #define SPACE_CHARS " \t\r\n"
 
 /**
-- 
1.9.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] lavf/aviobuf: add ff_get_line2() variant

2016-10-13 Thread Michael Niedermayer
On Thu, Oct 13, 2016 at 07:40:59PM +0200, Stefano Sabatini wrote:
> This allows to probe if the read line was partially discarded.
> ---
>  libavformat/aviobuf.c  | 10 +-
>  libavformat/internal.h | 14 ++
>  2 files changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index 134d627..28183b4 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -764,18 +764,26 @@ unsigned int avio_rb32(AVIOContext *s)
>  
>  int ff_get_line(AVIOContext *s, char *buf, int maxlen)
>  {
> -int i = 0;
> +return ff_get_line2(s, buf, maxlen, NULL);
> +}
> +
> +int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen)
> +{
> +int i = 0, j = 0;
>  char c;
>  
>  do {
>  c = avio_r8(s);
>  if (c && i < maxlen-1)
>  buf[i++] = c;
> +j++;
>  } while (c != '\n' && c != '\r' && c);

"\n" and "\0" would i belive both have a j=1 but they would have
differig i
is that intended ? (seems to me that this would make truncation
detection more annoying)
or am i missing something that avoids this difference?

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The educated differ from the uneducated as much as the living from the
dead. -- Aristotle 


signature.asc
Description: Digital signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH] lavf/aviobuf: add ff_get_line2() variant

2016-10-13 Thread Stefano Sabatini
This allows to probe if the read line was partially discarded.
---
 libavformat/aviobuf.c  | 10 +-
 libavformat/internal.h | 14 ++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 134d627..28183b4 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -764,18 +764,26 @@ unsigned int avio_rb32(AVIOContext *s)
 
 int ff_get_line(AVIOContext *s, char *buf, int maxlen)
 {
-int i = 0;
+return ff_get_line2(s, buf, maxlen, NULL);
+}
+
+int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen)
+{
+int i = 0, j = 0;
 char c;
 
 do {
 c = avio_r8(s);
 if (c && i < maxlen-1)
 buf[i++] = c;
+j++;
 } while (c != '\n' && c != '\r' && c);
 if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
 avio_skip(s, -1);
 
 buf[i] = 0;
+if (readlen)
+*readlen = j;
 return i;
 }
 
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 49244fa..cffc787 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -274,6 +274,20 @@ void ff_put_v(AVIOContext *bc, uint64_t val);
  */
 int ff_get_line(AVIOContext *s, char *buf, int maxlen);
 
+/**
+ * Read a whole line of text from AVIOContext. Stop reading after reaching
+ * either a \\n, a \\0 or EOF. The returned string is always \\0-terminated,
+ * and may be truncated if the buffer is too small.
+ *
+ * @param s the read-only AVIOContext
+ * @param buf buffer to store the read line
+ * @param maxlen size of the buffer
+ * @param readlen length of the read line, including the terminating newline 
character
+ * @return the length of the string written in the buffer, not including the
+ * final \\0
+ */
+int ff_get_line2(AVIOContext *s, char *buf, int maxlen, int *readlen);
+
 #define SPACE_CHARS " \t\r\n"
 
 /**
-- 
1.9.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel