Uninitialized variables; Fixed FP when bitmask is used on address

This commit is contained in:
Daniel Marjamäki 2021-05-24 20:55:04 +02:00
parent 0862045ef7
commit 4cccc710ef
2 changed files with 10 additions and 2 deletions

View File

@ -1120,7 +1120,9 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
const int arrayDim = (vartok->variable() && vartok->variable()->isArray()) ? vartok->variable()->dimensions().size() : 1;
int deref = 0;
derefValue = valueExpr;
while (Token::Match(derefValue->astParent(), "+|-|*|[|.") || (derefValue->astParent() && derefValue->astParent()->isCast())) {
while (Token::Match(derefValue->astParent(), "+|-|*|[|.") ||
(derefValue->astParent() && derefValue->astParent()->isCast()) ||
(deref < arrayDim && Token::Match(derefValue->astParent(), "&") && derefValue->astParent()->isBinaryOp())) {
const Token * const derefValueParent = derefValue->astParent();
if (derefValueParent->str() == "*") {
if (derefValueParent->isUnaryOp("*"))
@ -1133,7 +1135,7 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer,
else
break;
} else if (Token::Match(derefValueParent, "[+-]")) {
if (derefValueParent->valueType() && derefValueParent->valueType()->pointer == 0)
if (deref >= arrayDim)
break;
} else if (derefValueParent->str() == ".")
++deref;

View File

@ -1619,6 +1619,12 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void foo() {\n"
" char buf[1024];\n"
" char *b = (char *) (((uintptr_t) buf + 63) & ~(uintptr_t) 63);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// Passing array to function
checkUninitVar("void f(int i);\n"
"void foo()\n"