Skip to content

Commit bc89c29

Browse files
Partial fix for #15048 Inconsistent error severity for invalidFunctionArg (#8962)
1 parent 422e3d0 commit bc89c29

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎lib/checkfunctions.cpp‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,15 @@ void CheckFunctionsImpl::invalidFunctionArgError(const Token *tok, const std::st
222222
errmsg << " The value is " << std::setprecision(10) << (invalidValue->isIntValue() ? invalidValue->intvalue : invalidValue->floatValue) << " but the valid values are '" << validstr << "'.";
223223
else
224224
errmsg << " The value is 0 or 1 (boolean) but the valid values are '" << validstr << "'.";
225-
if (invalidValue)
225+
if (invalidValue) {
226+
const auto severity = invalidValue->errorSeverity() && invalidValue->isKnown() && !invalidValue->conditional ? Severity::error : Severity::warning;
226227
reportError(getErrorPath(tok, invalidValue, "Invalid argument"),
227-
invalidValue->errorSeverity() && invalidValue->isKnown() ? Severity::error : Severity::warning,
228+
severity,
228229
"invalidFunctionArg",
229230
errmsg.str(),
230231
CWE628,
231232
invalidValue->isInconclusive() ? Certainty::inconclusive : Certainty::normal);
232-
else
233+
} else
233234
reportError(tok,
234235
Severity::error,
235236
"invalidFunctionArg",

‎test/testfunctions.cpp‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class TestFunctions : public TestFixture {
5959

6060
// Invalid function argument
6161
TEST_CASE(invalidFunctionArg1);
62+
TEST_CASE(invalidFunctionArgErrorPath);
6263

6364
// Math function usage
6465
TEST_CASE(mathfunctionCall_fmod);
@@ -793,6 +794,22 @@ class TestFunctions : public TestFixture {
793794
ASSERT_EQUALS("", errout_str());
794795
}
795796

797+
void invalidFunctionArgErrorPath() {
798+
setMultiline();
799+
Settings s = settings;
800+
s.templateLocation = "{file}:{line}:note:{info}\n";
801+
check("double f(bool b) {\n"
802+
" double d = -1.0;\n"
803+
" if (b)\n"
804+
" return d;\n"
805+
" return std::log(d);\n"
806+
"}\n", s);
807+
ASSERT_EQUALS("[test.cpp:5:21]: warning: Invalid std::log() argument nr 1. The value is -1 but the valid values are '4.94066e-324:'. [invalidFunctionArg]\n"
808+
"[test.cpp:2:18]: note: Assignment 'd=-1.0', assigned value is -1.0\n"
809+
"[test.cpp:3:9]: note: Assuming condition is false\n"
810+
"[test.cpp:5:21]: note: Invalid argument\n", errout_str());
811+
}
812+
796813
void mathfunctionCall_sqrt() {
797814
// sqrt, sqrtf, sqrtl
798815
check("void foo()\n"

0 commit comments

Comments
 (0)