<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - False positive leading to "The result of the '/' expression is undefined""
href="https://bugs.llvm.org/show_bug.cgi?id=50272">50272</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>False positive leading to "The result of the '/' expression is undefined"
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>11.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Static Analyzer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>dcoughlin@apple.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>daniel@haxx.se
</td>
</tr>
<tr>
<th>CC</th>
<td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>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:
<a href="https://daniel.haxx.se/scan-build-2021-05-08-115719/report-0d7f93.html#EndPath">https://daniel.haxx.se/scan-build-2021-05-08-115719/report-0d7f93.html#EndPath</a>
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));</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>