Skip to content

Commit 8b64840

Browse files
Fix #13797 FN nullPointer with negated if-condition (regression) (danmar#8172)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent e282451 commit 8b64840

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

lib/checkunusedfunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ bool CheckUnusedFunctions::check(const Settings& settings, ErrorLogger& errorLog
385385
if (func.filename != "+")
386386
filename = func.filename;
387387
errors.emplace_back(filename, func.fileIndex, func.lineNumber, func.column, it->first);
388-
} else if (func.isC && !func.isStatic && !func.usedOtherFile) {
388+
} else if (func.isC && !func.isStatic) {
389389
std::string filename;
390390
if (func.filename != "+")
391391
filename = func.filename;

lib/library.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ Library::Error Library::load(const char exename[], const char path[], bool debug
210210
tinyxml2::XMLError error = xml_LoadFile(doc, fullfilename.c_str());
211211
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) {
212212
// only perform further lookups when the given path was not absolute
213-
if (!is_abs_path && error == tinyxml2::XML_ERROR_FILE_NOT_FOUND)
213+
if (!is_abs_path)
214214
{
215215
std::list<std::string> cfgfolders;
216216
#ifdef FILESDIR

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
10231023
if (var.isClass() && !var.isReference()) {
10241024
if (var.type()) {
10251025
// does this type need initialization?
1026-
if (var.type()->needInitialization == Type::NeedInitialization::True && !var.hasDefault() && !var.isStatic())
1026+
if (var.type()->needInitialization == Type::NeedInitialization::True && !var.hasDefault())
10271027
needInitialization = true;
10281028
else if (var.type()->needInitialization == Type::NeedInitialization::Unknown) {
10291029
if (!(var.valueType() && var.valueType()->type == ValueType::CONTAINER))

lib/vf_analyzers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ struct ValueFlowAnalyzer : Analyzer {
139139
return result;
140140
}
141141
ConditionState lhs = analyzeCondition(tok->astOperand1(), depth - 1);
142-
if (lhs.isUnknownDependent())
142+
if (lhs.isUnknownDependent() || !tok->astOperand2())
143143
return lhs;
144144
ConditionState rhs = analyzeCondition(tok->astOperand2(), depth - 1);
145145
if (rhs.isUnknownDependent())
@@ -1202,7 +1202,7 @@ struct SingleValueFlowAnalyzer : ValueFlowAnalyzer {
12021202
return false;
12031203
if (value.isImpossible())
12041204
return false;
1205-
if (isConditional() && !value.isKnown() && !value.isImpossible())
1205+
if (isConditional() && !value.isKnown())
12061206
return true;
12071207
if (value.isSymbolicValue())
12081208
return false;

test/testnullpointer.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,14 @@ class TestNullPointer : public TestFixture {
24582458
" if (h(i) && *i == 1) {}\n"
24592459
"}\n");
24602460
ASSERT_EQUALS("", errout_str());
2461+
2462+
check("void f(int i) {\n" // #13797
2463+
" int* p = nullptr;\n"
2464+
" if (!i) {\n"
2465+
" *p = 0;\n"
2466+
" }\n"
2467+
"}\n");
2468+
ASSERT_EQUALS("[test.cpp:4:10]: (error) Null pointer dereference: p [nullPointer]\n", errout_str());
24612469
}
24622470

24632471
void nullpointer78() // #7802
@@ -3929,7 +3937,8 @@ class TestNullPointer : public TestFixture {
39293937
" std::string s(p);\n"
39303938
" return s;\n"
39313939
"}\n", dinit(CheckOptions, $.inconclusive = true));
3932-
ASSERT_EQUALS("", errout_str());
3940+
ASSERT_EQUALS("[test.cpp:6:17]: (warning, inconclusive) Possible null pointer dereference: p [nullPointer]\n",
3941+
errout_str());
39333942

39343943
check("void f() {\n" // #11078
39353944
" const char* p = nullptr;\n"

0 commit comments

Comments
 (0)