From 47716ee4ca67d5c0c2972d8f30e339f5f3ac1c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 13 Jan 2012 07:26:56 +0100 Subject: [PATCH] Fixed #3497 (False positive: Uninitialized variable) --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 7a13b94bf..dbc41f16a 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -474,7 +474,7 @@ private: if (tok.varId()) { // array variable passed as function parameter.. if (Token::Match(tok.previous(), "[(,] %var% [+-,)]")) { - if (Token::Match(tok.previous(), "( %var% ) =")) + if (Token::Match(tok.previous(), "( %var% ) )| =")) ExecutionPath::bailOutVar(checks, tok.varId()); else use(checks, &tok); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 60607beb4..768201db8 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1132,6 +1132,13 @@ private: " printf(\"%s\", a);\n" "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str()); + + checkUninitVar("void f() {\n" // Ticket #3497 + " char header[1];\n" + " *((unsigned char*)(header)) = 0xff;\n" + " return header[0];\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } // alloc..