-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[clang] False positive clang-analyzer-core.DivideZero with loop over container #81734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@llvm/issue-subscribers-clang-static-analyzer Author: None (chrchr-github)
~~~c++
#include <vector>
int f(const std::vector<int>& v) {
if (v.empty())
return 0;
int h = 0;
for (auto it = v.begin(); it != v.end(); ++it) {
h = std::max(h, *it);
}
}
<source>:12:20: warning: Division by zero [clang-analyzer-core.DivideZero]
|
This is not a false positive about core.DivideZero.I think |
You're right that the false positive is produced because the analyzer doesn't recognize connection between In an ideal world a checker like |
There is an easier option for this problem. Anyways, there is an analyzer option called Downstream, we will definitely experiment with enabling this option, but one needs to be careful about checking if running times, memory footprint and the report changes improve / or are acceptable for the benefit. |
There could be division by zero if the vector holds only numbers <= 0. However, the diagnostic seems to imply that the vector might be empty, which is impossible.
Edit: also happens with
h = 1;
instead ofh = std::max(h, *it);
.https://godbolt.org/z/cbKh7axxd
The text was updated successfully, but these errors were encountered: