Re: [PATCH 1/3] http: offer to cast `size_t` to `curl_off_t` safely
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 21, 2025, 14:52 UTC
- Message-ID
- <xmqqfrcfx3g9.fsf@gitster.g>
- In-Reply-To
- <7caaec91020687f09764bbd50477c3fe889fcfed.1758457356.git.gitgitgadget@gmail.com>
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 10 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de> > > 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?
Show 5 quoted lines
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> > --- > http.h | 10 ++++++++++ > remote-curl.c | 14 +++----------- > 2 files changed, 13 insertions(+), 11 deletions(-)
Thanks; will queue.
Show 16 quoted lines
> +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;
> -}