From ab38ab800eea98b7fa4e36e9b6f219fab0cbbd8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 13 Sep 2015 17:31:45 +0200 Subject: [PATCH] CheckUninitVar: don't rely on Tokenizer::simplifyKnownVar() to simplify references --- lib/checkuninitvar.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 526b7be8c..26a397b1c 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -828,8 +828,14 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al } } - if (alloc == NO_ALLOC && Token::Match(vartok->previous(), "= %name% ;|%cop%")) - return true; + if (alloc == NO_ALLOC && Token::Match(vartok->previous(), "= %name% ;|%cop%")) { + // taking reference? + const Token *prev = vartok->tokAt(-2); + while (Token::Match(prev, "%name%|*")) + prev = prev->previous(); + if (!Token::Match(prev, "&")) + return true; + } bool unknown = false; if (pointer && CheckNullPointer::isPointerDeRef(vartok, unknown)) {