From: Junio C Hamano Date: Sun, 21 Sep 2025 14:52:54 GMT Subject: Re: [PATCH 1/3] http: offer to cast `size_t` to `curl_off_t` safely Message-ID: In-Reply-To: <7caaec91020687f09764bbd50477c3fe889fcfed.1758457356.git.gitgitgadget@gmail.com> "Johannes Schindelin via GitGitGadget" writes: > From: Johannes Schindelin > > 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 > --- > 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; > -}