diff --git a/cfg/std.cfg b/cfg/std.cfg index 9b5e134ef..f361de025 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -1057,7 +1057,7 @@ - + cbrt(arg1) false @@ -1068,7 +1068,7 @@ - + cbrt(arg1) false @@ -1079,7 +1079,7 @@ - + cbrt(arg1) false diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 8c072238f..4588f376a 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -730,6 +730,17 @@ static std::unordered_map createBuiltinLibr v.valueType = ValueFlow::Value::ValueType::FLOAT; return v; }; + functions["cbrt"] = [](const std::vector& 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::cbrt(value); + v.valueType = ValueFlow::Value::ValueType::FLOAT; + return v; + }; functions["exp"] = [](const std::vector& args) { if (args.size() != 1) return ValueFlow::Value::unknown(); diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 9b4d5b205..667879757 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -43,6 +43,20 @@ int zerodiv_sqrt() return 42 / i; } +int zerodiv_cbrt() +{ + int i = std::cbrt(0); + // cppcheck-suppress zerodiv + return 42 / i; +} + +int zerodiv_asin() +{ + int i = std::asin(0); + // cppcheck-suppress zerodiv + return 42 / i; +} + int zerodiv_acos() { int i = std::acos(1); @@ -78,6 +92,20 @@ int zerodiv_tanh() return 42 / i; } +int zerodiv_atanh() +{ + int i = std::atanh(0); + // cppcheck-suppress zerodiv + return 42 / i; +} + +int zerodiv_atan() +{ + int i = std::atan(0); + // cppcheck-suppress zerodiv + return 42 / i; +} + int zerodiv_sin() { int i = std::sin(0)+std::sin(M_PI)+std::sin(2*M_PI);