Fix 10121: False positive: Condition 'ab->a!=123' is always false when modifying an alias (#3293)

This commit is contained in:
Paul Fultz II 2021-08-01 03:10:11 -05:00 committed by GitHub
parent 6767b57d4c
commit 7d9fdf582b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -2428,7 +2428,7 @@ struct ExpressionAnalyzer : SingleValueFlowAnalyzer {
return;
visitAstNodes(start, [&](const Token* tok) {
for (const ValueFlow::Value& v : tok->values()) {
if (!v.isLocalLifetimeValue())
if (!(v.isLocalLifetimeValue() || (astIsPointer(tok) && v.isSymbolicValue() && v.isKnown())))
continue;
if (!v.tokvalue)
continue;

View File

@ -3642,6 +3642,27 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
// #10121
check("struct AB {\n"
" int a;\n"
"};\n"
"struct ABC {\n"
" AB* ab;\n"
"};\n"
"void g(ABC*);\n"
"int f(struct ABC *abc) {\n"
" int err = 0;\n"
" AB *ab = abc->ab;\n"
" if (ab->a == 123){\n"
" g(abc);\n"
" if (ab->a != 123) {\n"
" err = 1;\n"
" }\n"
" }\n"
" return err;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// #10323
check("void foo(int x) {\n"
" if(x)\n"