Merge branch 'main' of https://github.com/danmar/cppcheck into main
This commit is contained in:
commit
7d723a7a60
|
@ -182,8 +182,13 @@ bool CheckNullPointer::isPointerDeRef(const Token *tok, bool &unknown, const Set
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Dereferencing pointer..
|
// Dereferencing pointer..
|
||||||
if (parent->isUnaryOp("*") && !addressOf)
|
if (parent->isUnaryOp("*")) {
|
||||||
|
// declaration of function pointer
|
||||||
|
if (tok->variable() && tok->variable()->nameToken() == tok)
|
||||||
|
return false;
|
||||||
|
if (!addressOf)
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// array access
|
// array access
|
||||||
if (firstOperand && parent->str() == "[" && !addressOf)
|
if (firstOperand && parent->str() == "[" && !addressOf)
|
||||||
|
|
|
@ -1542,7 +1542,9 @@ void CppCheck::reportErr(const ErrorMessage &msg)
|
||||||
mErrorList.push_back(errmsg);
|
mErrorList.push_back(errmsg);
|
||||||
|
|
||||||
mErrorLogger.reportErr(msg);
|
mErrorLogger.reportErr(msg);
|
||||||
if (!mSettings.plistOutput.empty() && plistFile.is_open()) {
|
// check if plistOutput should be populated and the current output file is open and the error is not suppressed
|
||||||
|
if (!mSettings.plistOutput.empty() && plistFile.is_open() && !mSettings.nomsg.isSuppressed(errorMessage)) {
|
||||||
|
// add error to plist output file
|
||||||
plistFile << ErrorLogger::plistData(msg);
|
plistFile << ErrorLogger::plistData(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1137,6 +1137,15 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: f\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference: f\n", errout.str());
|
||||||
|
|
||||||
|
check("int* g();\n" // #11007
|
||||||
|
"int* f() {\n"
|
||||||
|
" static int* (*fun)() = 0;\n"
|
||||||
|
" if (!fun)\n"
|
||||||
|
" fun = g;\n"
|
||||||
|
" return fun();\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// loops..
|
// loops..
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" int *p = 0;\n"
|
" int *p = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue