Uninitialized variables; Passing address of uninitialized variable to function
This commit is contained in:
parent
8adfcc848c
commit
1e6a574cff
|
@ -1141,12 +1141,10 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
// FIXME handle address of!!
|
// FIXME handle address of!!
|
||||||
if (valueExpr->astParent()->isUnaryOp("&"))
|
|
||||||
return nullptr;
|
|
||||||
if (derefValue && derefValue->astParent() && derefValue->astParent()->isUnaryOp("&"))
|
if (derefValue && derefValue->astParent() && derefValue->astParent()->isUnaryOp("&"))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
// BAILOUT for binary &
|
// BAILOUT for binary & without parent
|
||||||
if (Token::simpleMatch(valueExpr->astParent(), "&") && astIsRhs(valueExpr) && Token::Match(valueExpr->astParent()->tokAt(-3), "( %name% ) &"))
|
if (Token::simpleMatch(valueExpr->astParent(), "&") && astIsRhs(valueExpr) && Token::Match(valueExpr->astParent()->tokAt(-3), "( %name% ) &"))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -1183,7 +1181,14 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
|
||||||
const int use = isFunctionParUsage(derefValue, false, NO_ALLOC, indirect);
|
const int use = isFunctionParUsage(derefValue, false, NO_ALLOC, indirect);
|
||||||
return (use>0) ? derefValue : nullptr;
|
return (use>0) ? derefValue : nullptr;
|
||||||
}
|
}
|
||||||
|
if (valueExpr->astParent()->isUnaryOp("&")) {
|
||||||
|
const Token *parent = valueExpr->astParent();
|
||||||
|
if (Token::Match(parent->astParent(), "[(,]") && (parent->astParent()->str() == "," || astIsRhs(parent))) {
|
||||||
|
const int use = isFunctionParUsage(valueExpr, pointer, alloc, indirect);
|
||||||
|
return (use>0) ? valueExpr : nullptr;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// Assignments;
|
// Assignments;
|
||||||
// * Is this LHS in assignment
|
// * Is this LHS in assignment
|
||||||
|
|
|
@ -3055,7 +3055,7 @@ private:
|
||||||
" char c;\n"
|
" char c;\n"
|
||||||
" a(&c);\n"
|
" a(&c);\n"
|
||||||
"}");
|
"}");
|
||||||
// FN ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout.str());
|
||||||
|
|
||||||
// pointer variable
|
// pointer variable
|
||||||
checkUninitVar("void a(char c);\n" // value => error
|
checkUninitVar("void a(char c);\n" // value => error
|
||||||
|
@ -3065,13 +3065,6 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout.str());
|
||||||
|
|
||||||
checkUninitVar("void a(const char *c);\n" // const value => error
|
|
||||||
"void b() {\n"
|
|
||||||
" char c;\n"
|
|
||||||
" a(&c);\n"
|
|
||||||
"}");
|
|
||||||
// FN ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c\n", errout.str());
|
|
||||||
|
|
||||||
|
|
||||||
checkUninitVar("void a(char *c);\n" // address => error
|
checkUninitVar("void a(char *c);\n" // address => error
|
||||||
"void b() {\n"
|
"void b() {\n"
|
||||||
|
|
Loading…
Reference in New Issue