[PATCH] debuginfod-client: Don't compare a double to a long

tbaeder@redhat.com tbaeder@redhat.com
Thu Mar 4 08:34:48 GMT 2021


From: Timm Bäder <tbaeder@redhat.com>

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
                     ^~~~~~~~~~~~~~~~~~~~
../../debuginfod/debuginfod-client.c:917:28: error: implicit conversion from 'long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Werror,-Wimplicit-int-float-conversion]
                pb = (cl > LONG_MAX ? LONG_MAX : (long)cl);
                         ~ ^~~~~~~~
/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
                     ^~~~~~~~~~~~~~~~~~~~
---
 debuginfod/debuginfod-client.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index de26af5b..df238e07 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 ? 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 ? LONG_MAX : (long)cl);
 #endif
             }
 
-- 
2.26.2



More information about the Elfutils-devel mailing list