[MPlayer-dev-eng] [PATCHv2 3/8] stream ftp: readline: Always try to read complete lines

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sun Nov 18 14:12:37 CET 2012


On Sat, Nov 17, 2012 at 01:01:58AM +0100, Alexander Strasser wrote:
> @@ -144,8 +149,20 @@ static int readline(char *buf,int max,struct stream_priv_s *ctl)
>  	}
>        }
>        if (max == 1) {
> -	*buf = '\0';
> -	break;
> +        int found_eol = 0;
> +
> +        while (ctl->cavail > 0) { // skip remaining response line
> +          found_eol = *ctl->cget == '\n';
> +          --ctl->cavail; ++ctl->cget;
> +
> +          if (found_eol) {
> +            break;
> +          }
> +        }
> +
> +        if (found_eol) {
> +	  break;
> +        }

I find this code quite non-obvious.
Maybe instead
char *eol = memchr(ctl->cget, ctl->cavail);
if (eol) {
  eol++;
  ctl->cavail -= eol - ctl->cget;
  ctl->cget = eol;
  break;
}
// read more data to find end of current line

I also wonder if we should do something against the
possibility that a hacked server could keep us in the
loop forever...

The rest of the patches are fine by me.


More information about the MPlayer-dev-eng mailing list