git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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;
> -}
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 3 of 12 in “Fix curl_easy_setopt() parameter type problem, again”
  1. 0/3 Fix curl_easy_setopt() parameter type problem, againJohannes Schindelin via GitGitGadget, Sep 21, 2025
  2. 1/3 http: offer to cast `size_t` to `curl_off_t` safelyJohannes Schindelin via GitGitGadget, Sep 21, 2025
  3. Junio C HamanoSep 21, 2025
  4. 2/3 imap-send: be more careful when casting to `curl_off_t`Johannes Schindelin via GitGitGadget, Sep 21, 2025
  5. Junio C HamanoSep 21, 2025
  6. 3/3 http-push: avoid new compile errorJohannes Schindelin via GitGitGadget, Sep 21, 2025
  7. Junio C HamanoSep 21, 2025
  8. 0/3 Fix curl_easy_setopt() parameter type problem, againJohannes Schindelin via GitGitGadget, Sep 26, 2025
  9. 1/3 http: offer to cast `size_t` to `curl_off_t` safelyJohannes Schindelin via GitGitGadget, Sep 26, 2025
  10. 2/3 imap-send: be more careful when casting to `curl_off_t`Johannes Schindelin via GitGitGadget, Sep 26, 2025
  11. 3/3 http-push: avoid new compile errorJohannes Schindelin via GitGitGadget, Sep 26, 2025
  12. Junio C HamanoSep 26, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.