diff mbox

[FFmpeg-devel,3/3] libavformat/aviobuf: don't treat 0 as EOF

Message ID 20170609134903.18069-1-daniel.kucera@gmail.com
State Superseded
Headers show

Commit Message

Daniel Kucera June 9, 2017, 1:49 p.m. UTC
Signed-off-by: Daniel Kucera <daniel.kucera@gmail.com>
---
 libavformat/aviobuf.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

Comments

Michael Niedermayer June 10, 2017, 1:58 a.m. UTC | #1
On Fri, Jun 09, 2017 at 03:49:03PM +0200, Daniel Kucera wrote:
> Signed-off-by: Daniel Kucera <daniel.kucera@gmail.com>
> ---
>  libavformat/aviobuf.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
> index 1667e9f08b..3705e406d9 100644
> --- a/libavformat/aviobuf.c
> +++ b/libavformat/aviobuf.c
> @@ -556,13 +556,14 @@ static void fill_buffer(AVIOContext *s)
>      if (s->read_packet)
>          len = s->read_packet(s->opaque, dst, len);
>      else
> -        len = 0;
> -    if (len <= 0) {
> +        len = AVERROR_EOF;
> +    if (len == AVERROR_EOF) {
>          /* do not modify buffer if EOF reached so that a seek back can
>             be done without rereading data */
>          s->eof_reached = 1;
> -        if (len < 0)
> -            s->error = len;
> +    } else if (len < 0) {
> +        s->eof_reached = 1;
> +        s->error= len;
>      } else {
>          s->pos += len;
>          s->buf_ptr = dst;
> @@ -630,13 +631,16 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size)
>                  // bypass the buffer and read data directly into buf
>                  if(s->read_packet)
>                      len = s->read_packet(s->opaque, buf, size);
> -
> -                if (len <= 0) {
> +		else

tabs are forbidden in ffmpeg git
also either this or the next patch cause fate to infinite-loop
(that is without any other patches)
if theres a dependance on the other patches please add a note about
that.

and are any changes needed in libavdevice ?
if so the ABI between them may add some more headaches

[...]
diff mbox

Patch

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 1667e9f08b..3705e406d9 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -556,13 +556,14 @@  static void fill_buffer(AVIOContext *s)
     if (s->read_packet)
         len = s->read_packet(s->opaque, dst, len);
     else
-        len = 0;
-    if (len <= 0) {
+        len = AVERROR_EOF;
+    if (len == AVERROR_EOF) {
         /* do not modify buffer if EOF reached so that a seek back can
            be done without rereading data */
         s->eof_reached = 1;
-        if (len < 0)
-            s->error = len;
+    } else if (len < 0) {
+        s->eof_reached = 1;
+        s->error= len;
     } else {
         s->pos += len;
         s->buf_ptr = dst;
@@ -630,13 +631,16 @@  int avio_read(AVIOContext *s, unsigned char *buf, int size)
                 // bypass the buffer and read data directly into buf
                 if(s->read_packet)
                     len = s->read_packet(s->opaque, buf, size);
-
-                if (len <= 0) {
+		else
+                    len = AVERROR_EOF;
+                if (len == AVERROR_EOF) {
                     /* do not modify buffer if EOF reached so that a seek back can
                     be done without rereading data */
                     s->eof_reached = 1;
-                    if(len<0)
-                        s->error= len;
+                    break;
+                } else if (len < 0) {
+                    s->eof_reached = 1;
+                    s->error= len;
                     break;
                 } else {
                     s->pos += len;