From: Timm Bäder Date: Sun, 7 Mar 2021 18:02:29 +0000 (-0500) Subject: debuginfod-client: Don't compare a double to a long X-Git-Tag: elfutils-0.184~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a51f2783716054ec2f6e501737f3f5058f7dbd80;p=thirdparty%2Felfutils.git debuginfod-client: Don't compare a double to a long Clang warns about this: ../../debuginfod/debuginfod-client.c:899:28: error: implicit conversion from 'long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Werror,-Wimplicit-int-float-conversion] pa = (dl > LONG_MAX ? LONG_MAX : (long)dl); ~ ^~~~~~~~ /usr/lib64/clang/10.0.1/include/limits.h:47:19: note: expanded from macro 'LONG_MAX' ^~~~~~~~~~~~ :38:22: note: expanded from here ^~~~~~~~~~~~~~~~~~~~ Modified for jakub's observation about LONG_MAX overflow. Signed-off-by: Timm Bäder --- diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 98089b2d9..56c2ec2b3 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,8 @@ +2021-03-07 Timm Bäder + + * debuginfod-client.c (debuginfod_query_server): Tweak + double/long clamping arithmetic to avoid UB and warnings. + 2021-02-25 Frank Ch. Eigler * debuginfod.cxx (handler_cb): Filter webapi for bad diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index 21dd37677..d5e7bbdfb 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -896,7 +896,7 @@ debuginfod_query_server (debuginfod_client *c, CURLINFO_SIZE_DOWNLOAD, &dl); if (curl_res == 0) - pa = (dl > LONG_MAX ? LONG_MAX : (long)dl); + pa = (dl >= (double)(LONG_MAX+1UL) ? LONG_MAX : (long)dl); #endif /* NB: If going through deflate-compressing proxies, this @@ -914,7 +914,7 @@ debuginfod_query_server (debuginfod_client *c, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &cl); if (curl_res == 0) - pb = (cl > LONG_MAX ? LONG_MAX : (long)cl); + pb = (cl >= (double)(LONG_MAX+1UL) ? LONG_MAX : (long)cl); #endif }