Fixed #4475 (New check: struct member is assigned a value that is not read)
This commit is contained in:
parent
858d9a18a7
commit
bf4e850e11
|
@ -47,7 +47,7 @@ void visitAstNodes(const Token *ast, std::function<ChildrenToVisit(const Token *
|
|||
break;
|
||||
if (c == ChildrenToVisit::op1 || c == ChildrenToVisit::op1_and_op2)
|
||||
tokens.push(tok->astOperand1());
|
||||
if (c == ChildrenToVisit::op1 || c == ChildrenToVisit::op1_and_op2)
|
||||
if (c == ChildrenToVisit::op2 || c == ChildrenToVisit::op1_and_op2)
|
||||
tokens.push(tok->astOperand2());
|
||||
}
|
||||
}
|
||||
|
@ -1260,7 +1260,11 @@ bool FwdAnalysis::isGlobalData(const Token *expr) const
|
|||
globalData = true;
|
||||
return ChildrenToVisit::none;
|
||||
}
|
||||
if ((tok->previous()->str() != "." && (!tok->variable()->isLocal() && !tok->variable()->isArgument())) || tok->variable()->isExtern()) {
|
||||
if (tok->variable()->isExtern()) {
|
||||
globalData = true;
|
||||
return ChildrenToVisit::none;
|
||||
}
|
||||
if (tok->previous()->str() != "." && !tok->variable()->isLocal() && !tok->variable()->isArgument()) {
|
||||
globalData = true;
|
||||
return ChildrenToVisit::none;
|
||||
}
|
||||
|
@ -1268,6 +1272,10 @@ bool FwdAnalysis::isGlobalData(const Token *expr) const
|
|||
globalData = true;
|
||||
return ChildrenToVisit::none;
|
||||
}
|
||||
if (tok->variable()->isPointerArray()) {
|
||||
globalData = true;
|
||||
return ChildrenToVisit::none;
|
||||
}
|
||||
}
|
||||
if (Token::Match(tok, ".|["))
|
||||
return ChildrenToVisit::op1;
|
||||
|
|
|
@ -1971,9 +1971,8 @@ private:
|
|||
|
||||
void localvar44() { // #4020 - FP
|
||||
functionVariableUsage("void func() {\n"
|
||||
" int *sp_mem[2] = { 0x00, 0x00 };\n"
|
||||
" int src = 1, dst = 2;\n"
|
||||
" sp_mem[(dst + i)][3] = src;\n"
|
||||
" int *sp_mem[2] = { global1, global2 };\n"
|
||||
" sp_mem[0][3] = 123;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
@ -4420,6 +4419,15 @@ private:
|
|||
"}"
|
||||
);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// Unknown struct type
|
||||
functionVariableUsage(
|
||||
"void fun() {"
|
||||
" struct FOO foo;\n"
|
||||
" foo.x = 123;\n"
|
||||
"}"
|
||||
);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'foo.x' is assigned a value that is never used.\n", errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue