Fixed zerodiv/moduloofone FNs for more math functions

This commit is contained in:
orbitcowboy 2022-07-09 22:36:17 +02:00
parent 8215521843
commit c117f62926
3 changed files with 179 additions and 30 deletions

View File

@ -733,7 +733,7 @@
<function name="tgamma,std::tgamma">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">tgamma(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -744,7 +744,7 @@
<function name="tgammaf,std::tgammaf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">tgamma(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -755,7 +755,7 @@
<function name="tgammal,std::tgammal">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">tgamma(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -766,7 +766,7 @@
<function name="trunc,std::trunc">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">trunc(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -777,7 +777,7 @@
<function name="truncf,std::truncf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">trunc(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -788,7 +788,7 @@
<function name="truncl,std::truncl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">trunc(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3344,7 +3344,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="logb,std::logb">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">logb(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3355,7 +3355,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="logbf,std::logbf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">logb(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3366,7 +3366,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="logbl,std::logbl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">logb(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3580,7 +3580,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="log1p,std::log1p">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">log1p(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3591,7 +3591,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="log1pf,std::log1pf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">log1p(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3602,7 +3602,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="log1pl,std::log1pl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">log1p(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3613,7 +3613,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="log2,std::log2">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">log2(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3625,7 +3625,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="log2f,std::log2f">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">log2(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3637,7 +3637,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="log2l,std::log2l">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">log2(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3649,7 +3649,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="nearbyint,std::nearbyint">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">nearbyint(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3660,7 +3660,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="nearbyintf,std::nearbyintf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">nearbyint(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3671,7 +3671,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="nearbyintl,std::nearbyintl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">nearbyint(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3682,7 +3682,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="nextafter,std::nextafter">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">nextafter(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3696,7 +3696,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="nextafterf,std::nextafterf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">nextafter(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3710,7 +3710,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="nextafterl,std::nextafterl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">nextafter(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3724,7 +3724,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="nexttoward,std::nexttoward">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">nexttoward(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3738,7 +3738,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="nexttowardf,std::nexttowardf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">nexttoward(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -3752,7 +3752,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="nexttowardl,std::nexttowardl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">nexttoward(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -4238,7 +4238,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="remainder,std::remainder">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">remainder(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -4253,7 +4253,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="remainderf,std::remainderf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">remainder(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -4268,7 +4268,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="remainderl,std::remainderl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">remainder(arg1,arg2)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -4604,7 +4604,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="round,std::round">
<use-retval/>
<pure/>
<returnValue type="double"/>
<returnValue type="double">round(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -4615,7 +4615,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="roundf,std::roundf">
<use-retval/>
<pure/>
<returnValue type="float"/>
<returnValue type="float">round(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">
@ -4626,7 +4626,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<function name="roundl,std::roundl">
<use-retval/>
<pure/>
<returnValue type="long double"/>
<returnValue type="long double">round(arg1)</returnValue>
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="in">

View File

@ -719,6 +719,39 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["remainder"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 2)
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::remainder(value, args[1].isFloatValue() ? args[1].floatValue : args[1].intvalue);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["nextafter"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 2)
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::nextafter(value, args[1].isFloatValue() ? args[1].floatValue : args[1].intvalue);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["nexttoward"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 2)
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::nexttoward(value, args[1].isFloatValue() ? args[1].floatValue : args[1].intvalue);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["hypot"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 2)
return ValueFlow::Value::unknown();
@ -785,6 +818,17 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["scalbln"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 2)
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::scalbln(value, args[1].isFloatValue() ? args[1].floatValue : args[1].intvalue);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["ldexp"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 2)
return ValueFlow::Value::unknown();
@ -939,6 +983,50 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["log1p"] = [](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::log1p(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["log2"] = [](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::log2(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["logb"] = [](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::logb(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["nearbyint"] = [](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::nearbyint(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["sinh"] = [](const std::vector<ValueFlow::Value>& args) {
if (args.size() != 1)
return ValueFlow::Value::unknown();
@ -1005,6 +1093,39 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["round"] = [](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::round(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["tgamma"] = [](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::tgamma(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
functions["trunc"] = [](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::trunc(value);
v.valueType = ValueFlow::Value::ValueType::FLOAT;
return v;
};
return functions;
}

View File

@ -99,6 +99,13 @@ int zerodiv_fdim()
return 42 / i;
}
int zerodiv_trunc()
{
int i = std::trunc(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_ceil()
{
int i = std::ceil(0);
@ -162,6 +169,27 @@ int zerodiv_acosh()
return 42 / i;
}
int zerodiv_log1p()
{
int i = std::log1p(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_nearbyint()
{
int i = std::nearbyint(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_round()
{
int i = std::round(0);
// cppcheck-suppress zerodiv
return 42 / i;
}
int zerodiv_sinh()
{
int i = std::sinh(0);