Subject: Re: [PATCH 1/9] xdiff: use ssize_t for dstart/dend, make them last in xdfile_t

From: Junio C Hamano <[email-masked]>
Date: Tue, 21 Oct 2025 10:18:56 -0700

Phillip Wood <[email-masked]> writes:

> On 15/10/2025 22:18, Ezekiel Newren via GitGitGadget wrote:
>> From: Ezekiel Newren <[email-masked]>
>> 
>> ssize_t is appropriate for dstart and dend because they both describe
>> positive or negative offsets relative to a pointer.
>
> Isn't ptrdiff_t the appropriate type for an offset to a pointer? ssize_t 
> is not guaranteed to be the same width as size_t (this has caused 
> problems in the past[1]) and is only defined by POSIX, not the C standard.
>
> Thanks
>
> Phillip
>
> [1] https://lore.kernel.org/git/[email-masked]/

Thanks for bringing up a very good point.

We often consider that a function that yields what we would normally
put in a size_t variable, when we _know_ that the return value would
not be so big to exceed half the range of size_t, can instead return
ssize_t and use the negative half of the range to signal error
conditions, but as the cited incident shows that it is an easy
mistake to make.