Re: [PATCH v2] http-backend: drop strbuf pre-sizing from get_info_packs()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 16, 2026, 15:24 UTC
- Message-ID
- <xmqqy0asn6j0.fsf@gitster.g>
- In-Reply-To
- <avqi2Jpd-QT5iNU9@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 11 quoted lines
>> This pre-sizing dates back to 2f4038ab33 (Git-aware CGI to provide dumb >> HTTP transport, 2009-10-30): `53` assumes the length of a SHA-1 >> "P pack-<hex>.pack\n" line (under-counting the 77-byte lines in SHA-256 >> repositories), and `cnt * 53 + 2` uses unchecked arithmetic. >> ... > Yeah, that's a much more convincing message. The other angle that this > is missing a bit is that giving a size hint ensures that we allocate > exactly as many bytes as we need. But that shouldn't matter in the > general case, and if you have to allocate gigabytes of memory to store > the list of packfiles... well, then you really have bigger problems to > worry about.
Yeah, miscounting the preallocation is not a bug and just doing pointless work. I agree with you that for the purpose of sizing strbuf, you have a larger issue if you have to worry about overflowing arithmetic.
> So I think this version is good enough, thanks!
Thanks.