Merge branch 'master' of https://github.com/danmar/cppcheck
This commit is contained in:
commit
4558fd5a2c
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -1166,7 +1166,7 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
|
|||
const Token *parent = tok;
|
||||
bool other = false;
|
||||
bool same = false;
|
||||
while (Token::Match(parent->astParent(), ".|::|[")) {
|
||||
while (Token::Match(parent->astParent(), "*|.|::|[")) {
|
||||
parent = parent->astParent();
|
||||
if (parent && isSameExpression(mCpp, false, expr, parent->astOperand1(), mLibrary, false, false, nullptr))
|
||||
same = true;
|
||||
|
@ -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;
|
||||
|
|
|
@ -5969,6 +5969,21 @@ private:
|
|||
" memptr = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Variable 'memptr' is reassigned a value before the old one has been used.\n", errout.str());
|
||||
|
||||
// Pointer function argument (#3857)
|
||||
check("void f(float * var)\n"
|
||||
"{\n"
|
||||
" var[0] = 0.2f;\n"
|
||||
" var[0] = 0.2f;\n" // <-- is initialized twice
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Variable 'var[0]' is reassigned a value before the old one has been used.\n", errout.str());
|
||||
|
||||
check("void f(float * var)\n"
|
||||
"{\n"
|
||||
" *var = 0.2f;\n"
|
||||
" *var = 0.2f;\n" // <-- is initialized twice
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Variable '*var' is reassigned a value before the old one has been used.\n", errout.str());
|
||||
}
|
||||
|
||||
void redundantVarAssignment_struct() {
|
||||
|
|
|
@ -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