From: Vaidas Pilkauskas Date: Tue, 17 Mar 2026 13:00:33 +0000 (+0000) Subject: strbuf: pass correct alloc to strbuf_attach() in strbuf_reencode() X-Git-Tag: v2.54.0-rc0~10^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bc6a6cf5eedb19b1b1da92ed2761ff9b1c7da627;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/strbuf.c b/strbuf.c index 59678bf5b0..bad76ea64d 100644 --- a/strbuf.c +++ b/strbuf.c @@ -168,7 +168,7 @@ int strbuf_reencode(struct strbuf *sb, const char *from, const char *to) if (!out) return -1; - strbuf_attach(sb, out, len, len); + strbuf_attach(sb, out, len, len + 1); return 0; }