From f23d880a7e27035452ca4ca24b0edf13b4c1faeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 1 Jan 2020 14:35:39 +0100 Subject: [PATCH] Verification; use configuration --- lib/exprengine.cpp | 15 +++++++++++++++ test/testsuites/danmar-verify/uninit.c | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/lib/exprengine.cpp b/lib/exprengine.cpp index 02be70dc6..27d2b2e62 100644 --- a/lib/exprengine.cpp +++ b/lib/exprengine.cpp @@ -1950,6 +1950,21 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer, break; } } + + // Uninitialized function argument.. + if (settings->library.isuninitargbad(parent->astOperand1(), num) && value.type == ExprEngine::ValueType::ArrayValue) { + const ExprEngine::ArrayValue &arrayValue = static_cast(value); + auto index0 = std::make_shared("0", 0, 0); + for (const auto &v: arrayValue.read(index0)) { + if (v.second->isUninit()) { + dataBase->addError(tok->linenr()); + std::list callstack{tok}; + ErrorLogger::ErrorMessage errmsg(callstack, &tokenizer->list, Severity::SeverityType::error, "verificationUninitArg", "There is function call, cannot determine that " + std::to_string(num) + getOrdinalText(num) + " argument is initialized.", CWE_USE_OF_UNINITIALIZED_VARIABLE, false); + errorLogger->reportErr(errmsg); + break; + } + } + } }; std::vector callbacks; diff --git a/test/testsuites/danmar-verify/uninit.c b/test/testsuites/danmar-verify/uninit.c index f1cbe94a2..ab73d26d8 100644 --- a/test/testsuites/danmar-verify/uninit.c +++ b/test/testsuites/danmar-verify/uninit.c @@ -19,6 +19,7 @@ int array2() { void local1() { int x; // cppcheck-suppress verificationUninit + // cppcheck-suppress uninitvar return x; } @@ -27,3 +28,8 @@ int pointer1(int *p) { return *p; } +void pointer2(char *p) { + // cppcheck-suppress verificationUninitArg + strlen(p); +} +