From cbbd7f0bd023194c58ea764ab3f7cbbc1fe3dc7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 23 May 2021 14:36:56 +0200 Subject: [PATCH] Uninitialized variables; Improved handling of function parameter --- lib/checkuninitvar.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index d2865d9f4..57a2f9e22 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1149,8 +1149,6 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, return nullptr; // FIXME handle address of!! - if (valueExpr->astParent()->isUnaryOp("&")) - return nullptr; if (derefValue && derefValue->astParent() && derefValue->astParent()->isUnaryOp("&")) return nullptr; @@ -1193,6 +1191,14 @@ const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, const int use = isFunctionParUsage(derefValue, false, NO_ALLOC, indirect); 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; // * Is this LHS in assignment @@ -1323,8 +1329,6 @@ int CheckUninitVar::isFunctionParUsage(const Token *vartok, bool pointer, Alloc return -1; return 1; } - if ((pointer || address) && alloc == NO_ALLOC && Token::Match(argStart, "const struct| %type% * %name% [,)]")) - return 1; if ((pointer || address) && Token::Match(argStart, "const %type% %name% [") && Token::Match(argStart->linkAt(3), "] [,)]")) return 1; }