Skip to content

Commit 87afe9a

Browse files
committed
lf_to_crlf_filter(): tell the caller we added "\n" when draining
This can only happen when the input size is multiple of the buffer size of the cascade filter (16k) and ends with an LF, but in such a case, the code forgot to tell the caller that it added the "\n" it could not add during the last round. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 284e3d2 commit 87afe9a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

convert.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ int is_null_stream_filter(struct stream_filter *filter)
879879

880880
struct lf_to_crlf_filter {
881881
struct stream_filter filter;
882-
int want_lf;
882+
unsigned want_lf:1;
883883
};
884884

885885
static int lf_to_crlf_filter_fn(struct stream_filter *filter,
@@ -895,8 +895,11 @@ static int lf_to_crlf_filter_fn(struct stream_filter *filter,
895895
lf_to_crlf->want_lf = 0;
896896
}
897897

898-
if (!input)
899-
return 0; /* We've already dealt with the state */
898+
/* We are told to drain */
899+
if (!input) {
900+
*osize_p -= o;
901+
return 0;
902+
}
900903

901904
count = *isize_p;
902905
if (count) {
@@ -931,10 +934,9 @@ static struct stream_filter_vtbl lf_to_crlf_vtbl = {
931934

932935
static struct stream_filter *lf_to_crlf_filter(void)
933936
{
934-
struct lf_to_crlf_filter *lf_to_crlf = xmalloc(sizeof(*lf_to_crlf));
937+
struct lf_to_crlf_filter *lf_to_crlf = xcalloc(1, sizeof(*lf_to_crlf));
935938

936939
lf_to_crlf->filter.vtbl = &lf_to_crlf_vtbl;
937-
lf_to_crlf->want_lf = 0;
938940
return (struct stream_filter *)lf_to_crlf;
939941
}
940942

0 commit comments

Comments
 (0)