diff --git a/cfg/std.cfg b/cfg/std.cfg index f361de025..16bf335c8 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -965,7 +965,7 @@ - + ceil(arg1) false @@ -976,7 +976,7 @@ - + ceil(arg1) false @@ -987,7 +987,7 @@ - + ceil(arg1) false diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 4588f376a..c00c4d5cc 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -741,6 +741,17 @@ static std::unordered_map createBuiltinLibr v.valueType = ValueFlow::Value::ValueType::FLOAT; return v; }; + functions["ceil"] = [](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::ceil(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 667879757..4f249cef8 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -36,6 +36,13 @@ #include #include +int zerodiv_ceil() +{ + int i = std::ceil(0); + // cppcheck-suppress zerodiv + return 42 / i; +} + int zerodiv_sqrt() { int i = std::sqrt(0);