Verification; Only warn about uninitialized function arguments if VERIFY_UNINIT is defined

This commit is contained in:
Daniel Marjamäki 2020-01-02 06:16:36 +01:00
parent e32c01b13c
commit 0e369edd8c
1 changed files with 4 additions and 2 deletions

View File

@ -206,7 +206,7 @@ namespace {
const Memory::iterator it = memory.find(tok->varId()); const Memory::iterator it = memory.find(tok->varId());
if (it != memory.end()) if (it != memory.end())
return std::dynamic_pointer_cast<ExprEngine::ArrayValue>(it->second); return std::dynamic_pointer_cast<ExprEngine::ArrayValue>(it->second);
if (tok->varId() == 0) if (tok->varId() == 0 || !tok->variable())
return std::shared_ptr<ExprEngine::ArrayValue>(); return std::shared_ptr<ExprEngine::ArrayValue>();
auto val = std::make_shared<ExprEngine::ArrayValue>(this, tok->variable()); auto val = std::make_shared<ExprEngine::ArrayValue>(this, tok->variable());
assignValue(tok, tok->varId(), val); assignValue(tok, tok->varId(), val);
@ -1952,7 +1952,8 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer,
} }
// Uninitialized function argument.. // Uninitialized function argument..
if (settings->library.isuninitargbad(parent->astOperand1(), num) && value.type == ExprEngine::ValueType::ArrayValue) { #ifdef VERIFY_UNINIT // This is highly experimental
if (settings->library.isuninitargbad(parent->astOperand1(), num) && settings->library.isnullargbad(parent->astOperand1(), num) && value.type == ExprEngine::ValueType::ArrayValue) {
const ExprEngine::ArrayValue &arrayValue = static_cast<const ExprEngine::ArrayValue &>(value); const ExprEngine::ArrayValue &arrayValue = static_cast<const ExprEngine::ArrayValue &>(value);
auto index0 = std::make_shared<ExprEngine::IntRange>("0", 0, 0); auto index0 = std::make_shared<ExprEngine::IntRange>("0", 0, 0);
for (const auto &v: arrayValue.read(index0)) { for (const auto &v: arrayValue.read(index0)) {
@ -1965,6 +1966,7 @@ void ExprEngine::runChecks(ErrorLogger *errorLogger, const Tokenizer *tokenizer,
} }
} }
} }
#endif
}; };
std::vector<ExprEngine::Callback> callbacks; std::vector<ExprEngine::Callback> callbacks;