Re: Infinite loop in cascade_filter_fn()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 26, 2011, 22:48 UTC
- Message-ID
- <7vy5v2wleb.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <20111125170219.GD10417@beez.lab.cmartin.tk>
Carlos Martín Nieto <cmn@elego.de> writes:
Show 11 quoted lines
> diff --git a/convert.c b/convert.c
> index 86e9c29..c050b86 100644
> --- a/convert.c
> +++ b/convert.c
> @@ -880,20 +880,29 @@ 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;
> + static int want_lf = 0;I do not think we want function scope static state anywhere in the cascade filter chain, as it will forbid us from running more than one output chain at the same time in the future. I think the correct way to structure it would be to create lf_to_crlf_filter as a proper subclass of stream_filter (see how cascade_filter_fn() casts its filter argument down to an instance of the cascade_filter class and uses it to keep track of its state) and keep this variable as its own filter state [*1*].
[Footnote]
*1* We currently use a singleton instance of lf_to_crlf_filter object because the implementation assumed there is no need for per-instance state.