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>
+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
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
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
}