From: René Scharfe Date: Fri, 15 May 2026 06:47:25 GMT Subject: Re: [PATCH] trailer: change strbuf in-place in unfold_value() Message-ID: <0b673b25-1f0e-44f5-b24c-7f7183d58cee@web.de> In-Reply-To: On 5/14/26 11:30 PM, Ramsay Jones wrote: > >> diff --git a/trailer.c b/trailer.c >> index 470f86a4a2..b89fa12fe7 100644 >> --- a/trailer.c >> +++ b/trailer.c >> @@ -988,29 +988,25 @@ static int ends_with_blank_line(const char *buf, size_t len) >> >> static void unfold_value(struct strbuf *val) >> { >> - struct strbuf out = STRBUF_INIT; >> size_t i; >> + size_t pos = 0; >> >> - strbuf_grow(&out, val->len); >> i = 0; >> while (i < val->len) { >> char c = val->buf[i++]; >> if (c == '\n') { >> /* Collapse continuation down to a single space. */ >> while (i < val->len && isspace(val->buf[i])) >> i++; >> - strbuf_addch(&out, ' '); >> - } else { >> - strbuf_addch(&out, c); >> + val->buf[pos++] = ' '; >> + } else if (pos != i) { > > Hmm, isn't 'pos' strictly (always) less than 'i' here? (note the post update > of 'i' when setting 'c' at the head of the loop). Ah, yes, good find. Initially I used a for loop which incremented i only at the end, but converted it back to minimize the patch and forgot to adjust this comparison. René