Fix 10121: False positive: Condition 'ab->a!=123' is always false when modifying an alias (#3293)
This commit is contained in:
parent
6767b57d4c
commit
7d9fdf582b
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue