diff options
author | Timm Bäder <tbaeder@redhat.com> | 2021-03-07 13:02:29 -0500 |
---|---|---|
committer | Frank Ch. Eigler <fche@redhat.com> | 2021-03-07 13:08:15 -0500 |
commit | a51f2783716054ec2f6e501737f3f5058f7dbd80 (patch) | |
tree | e78464ba0b65536c38ad059295f9816c9d670ae4 | |
parent | 619aae135aeccf81c5b59508823d379546e1d3b7 (diff) | |
download | elfutils-a51f2783716054ec2f6e501737f3f5058f7dbd80.tar.gz |
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'
^~~~~~~~~~~~
<built-in>:38:22: note: expanded from here
^~~~~~~~~~~~~~~~~~~~
Modified for jakub's observation about LONG_MAX overflow.
Signed-off-by: Timm Bäder <tbaeder@redhat.com>
-rw-r--r-- | debuginfod/ChangeLog | 5 | ||||
-rw-r--r-- | debuginfod/debuginfod-client.c | 4 |
2 files changed, 7 insertions, 2 deletions
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 98089b2d..56c2ec2b 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,8 @@ +2021-03-07 Timm Bäder <tbaeder@redhat.com> + + * debuginfod-client.c (debuginfod_query_server): Tweak + double/long clamping arithmetic to avoid UB and warnings. + 2021-02-25 Frank Ch. Eigler <fche@redhat.com> * debuginfod.cxx (handler_cb): Filter webapi for bad diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index 21dd3767..d5e7bbdf 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 } |