From 095f725b3cc3fcda4df1523f6fdff3befa340761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 27 Nov 2010 17:34:54 +0100 Subject: [PATCH] Fixed #2218 (False positive: Data is allocated but not initialized) --- lib/checkuninitvar.cpp | 8 +------- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index ab94ca328..01cf1f846 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -751,13 +751,7 @@ private: if (Token::simpleMatch(tok.next(), ".")) { - const Token *tok2 = tok.next(); - while (Token::Match(tok2, ". %var%")) - tok2 = tok2->tokAt(2); - if (tok2 && tok2->str() != "=" && tok.strAt(-1) != "&") - use_pointer(checks, &tok); - else - bailOutVar(checks, tok.varId()); + bailOutVar(checks, tok.varId()); return &tok; } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 585b8f07c..081d50bf4 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -999,6 +999,13 @@ private: "};\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar("void f()\n" + "{\n" + " Fred *fred = malloc(sizeof(Fred));\n" + " x(fred->f);\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("void foo(char *s)\n" "{\n" " char *a = malloc(100);\n"