Re: [PATCH 2/5] http: use `size_t` for byte position in fwrite_sha1_file
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 17, 2026, 04:10 UTC
- Message-ID
- <xmqqwlrharxf.fsf@gitster.g>
- In-Reply-To
- <395b47c0-6dc7-4a1b-b547-e5e68e7356f5@hogyros.de>
Simon Richter <Simon.Richter@hogyros.de> writes:
Show 5 quoted lines
>> I agree that changing the type of posn from int to size_t is the >> right move. > > It is a position in a file that is being read as binary data[1], so > off_t would be the best choice I think.
Hmm, interesting. The function writes out eltsize * nmemb (both are of type size_t) bytes, so the total could theoretically exceed the range that fits size_t.
But the thing is that posn is used this way
ssize_t retval = xwrite(freq->localfile, (char *) ptr + posn, size - posn);
to offset into a contiguous in-core region that starts at ptr. I am not sure if (ptr + posn) is still valid for posn that is too large to fit in size_t, though.
To put it differently, we are writing out what is in the contiguous in-core region and posn runs up to the allocation size of that region, which should be measured in size_t, no?