Re: Infinite loop in cascade_filter_fn()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 28, 2011, 19:18 UTC
- Message-ID
- <7vobvwukcv.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <20111128104812.GA2386@beez.lab.cmartin.tk>
Carlos Martín Nieto <cmn@elego.de> writes:
>> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="M9NhX3UHpAaciwkO" >> Content-Disposition: inline
Please do not do this. It makes it unnecessarily cumbersome to handle patches without adding much value to the patch.
Show 48 quoted lines
> --- 8< ---
> Subject: [PATCHv2] convert: track state in LF-to-CRLF filter
>
> There may not be enough space to store CRLF in the output. If we don't
> fill the buffer, then the filter will keep getting called with the same
> short buffer and will loop forever.
>
> Instead, always store the CR and record whether there's a missing LF
> if so we store it in the output buffer the next time the function gets
> called.
>
> Reported-by: Henrik Grubbström <grubba@roxen.com>
> Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
> ---
> convert.c | 50 +++++++++++++++++++++++++++++++++++++-------------
> 1 files changed, 37 insertions(+), 13 deletions(-)
>
> diff --git a/convert.c b/convert.c
> index 86e9c29..1c91409 100644
> --- a/convert.c
> +++ b/convert.c
> @@ -876,24 +876,39 @@ int is_null_stream_filter(struct stream_filter *filter)
> /*
> * LF-to-CRLF filter
> */
> +
> +struct lf_to_crlf_filter {
> + struct stream_filter filter;
> + int want_lf;
> +};
> +
> static int lf_to_crlf_filter_fn(struct stream_filter *filter,
> const char *input, size_t *isize_p,
> char *output, size_t *osize_p)
> {
> - size_t count;
> + size_t count, o = 0;
> + struct lf_to_crlf_filter *lfcrlf = (struct lf_to_crlf_filter *) filter;
> ...
> -};
> +static struct stream_filter *lf_to_crlf_filter(void)
> +{
> + struct lf_to_crlf_filter *lfcrlf = xmalloc(sizeof(*lfcrlf));
>
> + lfcrlf->filter.vtbl = &lf_to_crlf_vtbl;
> + lfcrlf->want_lf = 0;
> + return (struct stream_filter *)lfcrlf;
> +}Patch looks sane; you may want to rename the variable to lf_crlf at least, though. The name does not consist of three tokens ("lf", "cr" and "lf") but of two ("lf" and "crlf"), and your naming loses it.