diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index de2f2bff4..d2a3ce580 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -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; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 1e8dc6042..414ba2457 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -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"