From 234b1e00980d624cd73b26c9e11c97799500aa02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 30 Nov 2010 18:40:36 +0100 Subject: [PATCH] Fixed #2265 (False positive: Uninitialized variable: path) --- lib/checkuninitvar.cpp | 15 +++++++++++---- test/testuninitvar.cpp | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 01cf1f846..ba3f99f08 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -379,12 +379,19 @@ private: !Token::simpleMatch(tok2->next(), "=")) { // Multiple assignments.. - if (Token::simpleMatch(tok2->next(), "[")) + if (Token::Match(tok2->next(), ".|[")) { const Token * tok3 = tok2; - while (Token::simpleMatch(tok3->next(), "[")) - tok3 = tok3->next()->link(); - if (Token::simpleMatch(tok3, "] =")) + while (tok3) + { + if (Token::Match(tok3->next(), ". %var%")) + tok3 = tok3->tokAt(2); + else if (tok3->strAt(1) == "[") + tok3 = tok3->next()->link(); + else + break; + } + if (tok3->strAt(1) == "=") continue; } bool foundError; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 081d50bf4..570885d63 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1108,6 +1108,12 @@ private: " return i;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar("void f(int x) {\n" + " struct AB ab;\n" + " x = ab.x = 12;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } // enum..