[llvm-bugs] [Bug 50272] New: False positive leading to "The result of the '/' expression is undefined"
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat May 8 03:55:20 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=50272
Bug ID: 50272
Summary: False positive leading to "The result of the '/'
expression is undefined"
Product: clang
Version: 11.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Static Analyzer
Assignee: dcoughlin at apple.com
Reporter: daniel at haxx.se
CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org
Using scan-build-11 in Debian unstable (based on clang 11.0.1-2) on current
curl code (in curl's git master as of May 7th).
scan-build complains on a code path that protects against integer overflows and
division by zero but still somehow scan-build is not content. No earlier
versions of scan-build (and no other code analyzer we use) warn on this code.
Here's the saved scan-build output:
https://daniel.haxx.se/scan-build-2021-05-08-115719/report-0d7f93.html#EndPath
I'm working around this false positive by putting (the same) logic into a
function, which if it was a genuine problem also would be weird...
The code that causes two warnings look like this:
/* returns TRUE if it's time to show the progress meter */
static bool progress_calc(struct Curl_easy *data, struct curltime now)
{
curl_off_t timespent;
curl_off_t timespent_ms; /* milliseconds */
curl_off_t dl = data->progress.downloaded;
curl_off_t ul = data->progress.uploaded;
bool timetoshow = FALSE;
/* The time spent so far (from the start) */
data->progress.timespent = Curl_timediff_us(now, data->progress.start);
timespent = (curl_off_t)data->progress.timespent/1000000; /* seconds */
timespent_ms = (curl_off_t)data->progress.timespent/1000; /* ms */
/* The average download speed this far */
if(dl < CURL_OFF_T_MAX/1000000)
data->progress.dlspeed =
(dl * 1000000 / (data->progress.timespent?data->progress.timespent:1));
else if(dl < CURL_OFF_T_MAX/1000)
data->progress.dlspeed = (dl * 1000 / (timespent_ms>0?timespent_ms:1));
else
data->progress.dlspeed = (dl / (timespent>0?timespent:1));
/* The average upload speed this far */
if(ul < CURL_OFF_T_MAX/1000000)
data->progress.ulspeed =
(ul * 1000000 / (data->progress.timespent?data->progress.timespent:1));
else if(ul < CURL_OFF_T_MAX/1000)
data->progress.ulspeed = (ul * 1000 / (timespent_ms>0?timespent_ms:1));
else
data->progress.ulspeed = (ul / (timespent>0?timespent:1));
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210508/0f6651b8/attachment-0001.html>
More information about the llvm-bugs
mailing list