diff options
| author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2025-09-26 10:32:50 +0000 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-09-26 10:38:18 -0700 |
| commit | e4efcd70604f2a294e020ec2e1bc38f01892cd19 (patch) | |
| tree | 1dae914f2c90b332b2bd617902485e00204af09e /http.h | |
| parent | f368df439b31b422169975cc3c95f7db6a46eada (diff) | |
| download | git-e4efcd70604f2a294e020ec2e1bc38f01892cd19.tar.xz | |
http: offer to cast `size_t` to `curl_off_t` safely
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`.
With this move, `gettext.h` must be `#include`d in `http.h` to allow the
error message to remain translatable.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'http.h')
| -rw-r--r-- | http.h | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -8,6 +8,7 @@ struct packed_git; #include <curl/curl.h> #include <curl/easy.h> +#include "gettext.h" #include "strbuf.h" #include "remote.h" @@ -95,6 +96,15 @@ static inline int missing__target(int code, int result) #define missing_target(a) missing__target((a)->http_code, (a)->curl_result) +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; +} + /* * Normalize curl results to handle CURL_FAILONERROR (or lack thereof). Failing * http codes have their "result" converted to CURLE_HTTP_RETURNED_ERROR, and |
