Skip to content

Commit cb8010b

Browse files
tboegigitster
authored andcommitted
remote-curl.c: xcurl_off_t is not portable (on 32 bit platfoms)
When setting DEVELOPER = 1 DEVOPTS = extra-all "gcc (Raspbian 6.3.0-18+rpi1+deb9u1) 6.3.0 20170516" errors out with "comparison is always false due to limited range of data type" "[-Werror=type-limits]" It turns out that the function xcurl_off_t() has 2 flavours: - It gives a warning 32 bit systems, like Linux - It takes the signed ssize_t as a paramter, but the only caller is using a size_t (which is typically unsigned these days) The original motivation of this function is to make sure that sizes > 2GiB are handled correctly. The curl documentation says: "For any given platform/compiler curl_off_t must be typedef'ed to a 64-bit wide signed integral data type" On a 32 bit system "size_t" can be promoted into a 64 bit signed value without loss of data, and therefore we may see the "comparison is always false" warning. On a 64 bit system it may happen, at least in theory, that size_t is > 2^63, and then the promotion from an unsigned "size_t" into a signed "curl_off_t" may be a problem. One solution to suppress a possible compiler warning could be to remove the function xcurl_off_t(). However, to be on the very safe side, we keep it and improve it: - The len parameter is changed from ssize_t to size_t - A temporally variable "size" is used, promoted int uintmax_t and the compared with "maximum_signed_value_of_type(curl_off_t)". Thanks to Junio C Hamano for this hint. Signed-off-by: Torsten Bögershausen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8858448 commit cb8010b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

remote-curl.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,11 @@ static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
617617
return err;
618618
}
619619

620-
static curl_off_t xcurl_off_t(ssize_t len) {
621-
if (len > maximum_signed_value_of_type(curl_off_t))
620+
static curl_off_t xcurl_off_t(size_t len) {
621+
uintmax_t size = len;
622+
if (size > maximum_signed_value_of_type(curl_off_t))
622623
die("cannot handle pushes this big");
623-
return (curl_off_t) len;
624+
return (curl_off_t)size;
624625
}
625626

626627
static int post_rpc(struct rpc_state *rpc)

0 commit comments

Comments
 (0)