diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 7edaff6c241..f6daec51f20 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -385,7 +385,7 @@ bool CheckUnusedFunctions::check(const Settings& settings, ErrorLogger& errorLog if (func.filename != "+") filename = func.filename; errors.emplace_back(filename, func.fileIndex, func.lineNumber, func.column, it->first); - } else if (func.isC && !func.isStatic && !func.usedOtherFile) { + } else if (func.isC && !func.isStatic) { std::string filename; if (func.filename != "+") filename = func.filename; diff --git a/lib/library.cpp b/lib/library.cpp index ad5ea13a3ed..5b6af91ac4a 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -210,7 +210,7 @@ Library::Error Library::load(const char exename[], const char path[], bool debug tinyxml2::XMLError error = xml_LoadFile(doc, fullfilename.c_str()); if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) { // only perform further lookups when the given path was not absolute - if (!is_abs_path && error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) + if (!is_abs_path) { std::list cfgfolders; #ifdef FILESDIR diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index e1f7a28d68d..05dd605ea21 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1023,7 +1023,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization() if (var.isClass() && !var.isReference()) { if (var.type()) { // does this type need initialization? - if (var.type()->needInitialization == Type::NeedInitialization::True && !var.hasDefault() && !var.isStatic()) + if (var.type()->needInitialization == Type::NeedInitialization::True && !var.hasDefault()) needInitialization = true; else if (var.type()->needInitialization == Type::NeedInitialization::Unknown) { if (!(var.valueType() && var.valueType()->type == ValueType::CONTAINER)) diff --git a/lib/vf_analyzers.cpp b/lib/vf_analyzers.cpp index e14af7a9c98..ec026f2f487 100644 --- a/lib/vf_analyzers.cpp +++ b/lib/vf_analyzers.cpp @@ -139,7 +139,7 @@ struct ValueFlowAnalyzer : Analyzer { return result; } ConditionState lhs = analyzeCondition(tok->astOperand1(), depth - 1); - if (lhs.isUnknownDependent()) + if (lhs.isUnknownDependent() || !tok->astOperand2()) return lhs; ConditionState rhs = analyzeCondition(tok->astOperand2(), depth - 1); if (rhs.isUnknownDependent()) @@ -1202,7 +1202,7 @@ struct SingleValueFlowAnalyzer : ValueFlowAnalyzer { return false; if (value.isImpossible()) return false; - if (isConditional() && !value.isKnown() && !value.isImpossible()) + if (isConditional() && !value.isKnown()) return true; if (value.isSymbolicValue()) return false; diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 1eb01edfcce..96e188075e4 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -2458,6 +2458,14 @@ class TestNullPointer : public TestFixture { " if (h(i) && *i == 1) {}\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("void f(int i) {\n" // #13797 + " int* p = nullptr;\n" + " if (!i) {\n" + " *p = 0;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4:10]: (error) Null pointer dereference: p [nullPointer]\n", errout_str()); } void nullpointer78() // #7802 @@ -3929,7 +3937,8 @@ class TestNullPointer : public TestFixture { " std::string s(p);\n" " return s;\n" "}\n", dinit(CheckOptions, $.inconclusive = true)); - ASSERT_EQUALS("", errout_str()); + ASSERT_EQUALS("[test.cpp:6:17]: (warning, inconclusive) Possible null pointer dereference: p [nullPointer]\n", + errout_str()); check("void f() {\n" // #11078 " const char* p = nullptr;\n"