]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
debuginfod-client: Don't compare a double to a long
authorTimm Bäder <tbaeder@redhat.com>
Sun, 7 Mar 2021 18:02:29 +0000 (13:02 -0500)
committerFrank Ch. Eigler <fche@redhat.com>
Sun, 7 Mar 2021 18:08:15 +0000 (13:08 -0500)
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>
debuginfod/ChangeLog
debuginfod/debuginfod-client.c

index 98089b2d97bc3282aed74da722893f8a27341d5a..56c2ec2b33fb3b0f07b6e214a32e03480de02c3b 100644 (file)
@@ -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
index 21dd37677997482dbe22fc359977c686da7b0b99..d5e7bbdfbe1b1cc79d3c62cf71ffdd6532bb4404 100644 (file)
@@ -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
             }