From 2ee819f8b8eed3b85313e32d58299d85ef039c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 2 Dec 2026 15:07:26 +0100 Subject: [PATCH 1/3] test --- test/testfunctions.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/testfunctions.cpp b/test/testfunctions.cpp index 58228b58b07..6d09929c34f 100644 --- a/test/testfunctions.cpp +++ b/test/testfunctions.cpp @@ -60,6 +60,7 @@ class TestFunctions : public TestFixture { // Invalid function argument TEST_CASE(invalidFunctionArg1); TEST_CASE(invalidFunctionArgErrorPath); + TEST_CASE(invalidFunctionArgNonFinite); // Math function usage TEST_CASE(mathfunctionCall_fmod); @@ -810,6 +811,24 @@ class TestFunctions : public TestFixture { "[test.cpp:5:21]: note: Invalid argument\n", errout_str()); } + void invalidFunctionArgNonFinite() { + check("void f() {\n" + " double c = 0.9;\n" + " c = asin(c);\n" + " c = asin(c);\n" + " c = asin(c);\n" + "}\n" + "void g() {\n" + " double c = 1e300;\n" + " c = c * c;\n" + " c = asin(c);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4:14]: (error) Invalid asin() argument nr 1. The value is 1.119769515 but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" + "[test.cpp:5:14]: (error) Invalid asin() argument nr 1. The value is nan but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n" + "[test.cpp:10:14]: (error) Invalid asin() argument nr 1. The value is inf but the valid values are '-1.0:1.0'. [invalidFunctionArg]\n", + errout_str()); + } + void mathfunctionCall_sqrt() { // sqrt, sqrtf, sqrtl check("void foo()\n" From 0839ef4c803fd8c4cf17aa8ee9a2b2a80866c6dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 2 Dec 2026 15:07:32 +0100 Subject: [PATCH 2/3] fix --- lib/library.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/library.cpp b/lib/library.cpp index 6c80e88e5cc..356eabffa4d 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -1151,10 +1152,10 @@ bool Library::isFloatArgValid(const Token *ftok, int argnr, double argvalue, con return true; if ((!tok->previous() || tok->strAt(-1) == ",") && Token::Match(tok,": %num%") && argvalue <= MathLib::toDoubleNumber(tok->tokAt(1))) return true; - if (Token::Match(tok, "%num%") && MathLib::isFloat(tok->str()) && MathLib::isEqual(tok->str(), MathLib::toString(argvalue))) + if (Token::Match(tok, "%num%") && MathLib::isFloat(tok->str()) && std::isfinite(argvalue) && MathLib::isEqual(tok->str(), MathLib::toString(argvalue))) return true; if (Token::Match(tok, "! %num%") && MathLib::isFloat(tok->strAt(1))) - return MathLib::isNotEqual(tok->strAt(1), MathLib::toString(argvalue)); + return !std::isfinite(argvalue) || MathLib::isNotEqual(tok->strAt(1), MathLib::toString(argvalue)); } return false; } From 48863a1dc758092d1492b4a4edb06c3713954a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 2 Dec 2026 15:19:34 +0100 Subject: [PATCH 3/3] consistent error message across libc implementations --- lib/checkfunctions.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/checkfunctions.cpp b/lib/checkfunctions.cpp index 89094b6bf4c..f7ea34091c5 100644 --- a/lib/checkfunctions.cpp +++ b/lib/checkfunctions.cpp @@ -35,6 +35,7 @@ #include "valueflow.h" #include "vfvalue.h" +#include #include #include #include @@ -218,9 +219,14 @@ void CheckFunctionsImpl::invalidFunctionArgError(const Token *tok, const std::st << " or $symbol() argument nr " << argnr << " can have invalid value."; else errmsg << "Invalid $symbol() argument nr " << argnr << '.'; - if (invalidValue) - errmsg << " The value is " << std::setprecision(10) << (invalidValue->isIntValue() ? invalidValue->intvalue : invalidValue->floatValue) << " but the valid values are '" << validstr << "'."; - else + if (invalidValue) { + errmsg << " The value is "; + if (!invalidValue->isIntValue() && std::isnan(invalidValue->floatValue)) + errmsg << "nan"; + else + errmsg << std::setprecision(10) << (invalidValue->isIntValue() ? invalidValue->intvalue : invalidValue->floatValue); + errmsg << " but the valid values are '" << validstr << "'."; + } else errmsg << " The value is 0 or 1 (boolean) but the valid values are '" << validstr << "'."; if (invalidValue) { const auto severity = invalidValue->errorSeverity() && invalidValue->isKnown() && !invalidValue->conditional ? Severity::error : Severity::warning;