diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 63ac7ccf3..a591100f1 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1600,6 +1600,13 @@ private: if (tok.varId()) { + // Used.. + if (Token::Match(tok.previous(), "[[+-*/] %var% []+-*/]")) + { + use(foundError, checks, &tok); + return &tok; + } + if (Token::Match(tok.previous(), "[;{}] %var% =")) { // using same variable rhs? @@ -1663,7 +1670,7 @@ private: const Token *tok2 = tok.next()->link(); if (Token::simpleMatch(tok2 ? tok2->next() : 0, "=")) { - ExecutionPath::bailOut(checks); + ExecutionPath::bailOutVar(checks, tok.varId()); return &tok; } } diff --git a/test/testother.cpp b/test/testother.cpp index a35808206..66d70c00d 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1092,6 +1092,14 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: i\n", errout.str()); + checkUninitVar("static void foo()\n" + "{\n" + " int ar[10];\n" + " int i;\n" + " ar[i] = 0;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: i\n", errout.str()); + checkUninitVar("static void foo()\n" "{\n" " int x, y;\n"