Fixed zerodiv FN for '1/std::ceil(0)'

This commit is contained in:
orbitcowboy 2022-07-09 17:32:32 +02:00
parent 41b6452604
commit c777cd5060
3 changed files with 21 additions and 3 deletions

View File

@ -965,7 +965,7 @@
<function name="ceil,std::ceil"> <function name="ceil,std::ceil">
<use-retval/> <use-retval/>
<pure/> <pure/>
<returnValue type="double"/> <returnValue type="double">ceil(arg1)</returnValue>
<noreturn>false</noreturn> <noreturn>false</noreturn>
<leak-ignore/> <leak-ignore/>
<arg nr="1" direction="in"> <arg nr="1" direction="in">
@ -976,7 +976,7 @@
<function name="ceilf,std::ceilf"> <function name="ceilf,std::ceilf">
<use-retval/> <use-retval/>
<pure/> <pure/>
<returnValue type="float"/> <returnValue type="float">ceil(arg1)</returnValue>
<noreturn>false</noreturn> <noreturn>false</noreturn>
<leak-ignore/> <leak-ignore/>
<arg nr="1" direction="in"> <arg nr="1" direction="in">
@ -987,7 +987,7 @@
<function name="ceill,std::ceill"> <function name="ceill,std::ceill">
<use-retval/> <use-retval/>
<pure/> <pure/>
<returnValue type="long double"/> <returnValue type="long double">ceil(arg1)</returnValue>
<noreturn>false</noreturn> <noreturn>false</noreturn>
<leak-ignore/> <leak-ignore/>
<arg nr="1" direction="in"> <arg nr="1" direction="in">

View File

@ -741,6 +741,17 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
v.valueType = ValueFlow::Value::ValueType::FLOAT; v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v; return v;
}; };
functions["ceil"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 1)
return ValueFlow::Value::unknown();
ValueFlow::Value v = args[0];
if (!v.isFloatValue() && !v.isIntValue())
return ValueFlow::Value::unknown();
double value = args[0].isFloatValue() ? args[0].floatValue : args[0].intvalue;
v.floatValue = std::ceil(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["exp"] = [](const std::vector<ValueFlow::Value>& args) { functions["exp"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 1) if (args.size() != 1)
return ValueFlow::Value::unknown(); return ValueFlow::Value::unknown();

View File

@ -36,6 +36,13 @@
#include <iterator> #include <iterator>
#include <vector> #include <vector>
int zerodiv_ceil()
{
int i = std::ceil(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_sqrt() int zerodiv_sqrt()
{ {
int i = std::sqrt(0); int i = std::sqrt(0);