From 6b489230e867fcca24be38ef5ca48d63b390b7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 12 Nov 2010 16:11:44 +0100 Subject: [PATCH] Fixed #2188 (Does not detect initialization) --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 1beb26ea5..07e90a25e 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -673,7 +673,7 @@ private: bailouts.insert(tok2->varId()); // array initialization.. - if (Token::Match(tok2->previous(), "[,(] %var% +")) + if (Token::Match(tok2->previous(), "[,(] %var% [+-]")) { // if var is array, bailout for (std::list::const_iterator it = checks.begin(); it != checks.end(); ++it) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index a45e9fa83..0d2c3ffc8 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -879,6 +879,14 @@ private: " s = y[0]*y[1];\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar("void foo()\n" + "{\n" + " int a[2];\n" + " init(a - 1);\n" + " int b = a[0];\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } // alloc..