Subject: Re: [PATCH 1/3] http: offer to cast `size_t` to `curl_off_t` safely

From: Junio C Hamano <[email-masked]>
Date: Sun, 21 Sep 2025 07:52:54 -0700

"Johannes Schindelin via GitGitGadget" <[email-masked]>
writes:

> From: Johannes Schindelin <[email-masked]>
>
> This commit moves the `xcurl_off_t()` function, which validates that a
> given value fits within the `curl_off_t` data type and then casts it, to
> a more central place so that it can be used outside of `remote-curl.c`,
> too.
>
> At the same time, this function is renamed to conform better with the
> naming convention of the helper functions that safely cast from one data
> type to another which has been well established in `git-compat-util.h`.

OK.  The code inside the renamed function is the same with an
updated message to show the value.

> With this move, the error message can unfortunately no longer be renamed
> because the `_(...)` function is not available at the time of
> definition.

It is not clear to me what change (or lack thereof?) in this patch
this paragraph refers to.  Who wants to rename what error message
and why?

> Signed-off-by: Johannes Schindelin <[email-masked]>
> ---
>  http.h        | 10 ++++++++++
>  remote-curl.c | 14 +++-----------
>  2 files changed, 13 insertions(+), 11 deletions(-)

Thanks; will queue.

> +static inline curl_off_t cast_size_t_to_curl_off_t(size_t a)
> +{
> +	uintmax_t size = a;
> +	if (size > maximum_signed_value_of_type(curl_off_t))
> +		die(_("number too large to represent as curl_off_t "
> +		      "on this platform: %"PRIuMAX), (uintmax_t)a);
> +	return (curl_off_t)a;
> +}
> +
> -static curl_off_t xcurl_off_t(size_t len)
> -{
> -	uintmax_t size = len;
> -	if (size > maximum_signed_value_of_type(curl_off_t))
> -		die(_("cannot handle pushes this big"));
> -	return (curl_off_t)size;
> -}