strbuf: pass correct alloc to strbuf_attach() in strbuf_reencode()

reencode_string_len() allocates len+1 bytes (including the NUL) and returns the string length in len. strbuf_reencode() was calling strbuf_attach(sb, out, len, len), so alloc was one byte too small. strbuf_attach() then calls strbuf_grow(sb, 0). With alloc < len+1, ALLOC_GROW always reallocates, so we reallocated immediately after attach even when the strbuf was not extended further. Pass len+1 as the alloc argument so the existing buffer is reused and the reallocation is avoided. Signed-off-by: Vaidas Pilkauskas <vaidas.pilkauskas@shopify.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vaidas Pilkauskas committed Mar 17, 2026 at 13:00 UTC bc6a6cf5eedb19b1b1da92ed2761ff9b1c7da627
1 file changed +1 -1
strbuf.c
+1 -1
@@ -168,7 +168,7 @@ int strbuf_reencode(struct strbuf *sb, const char *from, const char *to)
168 if (!out)
169 return -1;
170
171 - strbuf_attach(sb, out, len, len);
171 + strbuf_attach(sb, out, len, len + 1);
172 return 0;
173 }
174