Skip to content

Commit ab38ab8

Browse files
committed
CheckUninitVar: don't rely on Tokenizer::simplifyKnownVar() to simplify references
1 parent ad007ca commit ab38ab8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/checkuninitvar.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,14 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
828828
}
829829
}
830830

831-
if (alloc == NO_ALLOC && Token::Match(vartok->previous(), "= %name% ;|%cop%"))
832-
return true;
831+
if (alloc == NO_ALLOC && Token::Match(vartok->previous(), "= %name% ;|%cop%")) {
832+
// taking reference?
833+
const Token *prev = vartok->tokAt(-2);
834+
while (Token::Match(prev, "%name%|*"))
835+
prev = prev->previous();
836+
if (!Token::Match(prev, "&"))
837+
return true;
838+
}
833839

834840
bool unknown = false;
835841
if (pointer && CheckNullPointer::isPointerDeRef(vartok, unknown)) {

0 commit comments

Comments
 (0)