From 469a8e40322eebb97ac686ead8ffedc7db4dff64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 15 Nov 2009 20:01:57 +0100 Subject: [PATCH] Fixed #925 (uninitialized deletion not detected) --- lib/checkother.cpp | 6 ++++++ test/testother.cpp | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 46b3a24a0..92a530dac 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1317,6 +1317,12 @@ static const Token *uninitvar_checkscope(const Token * const tokens, const Token return 0; } } + + if (Token::simpleMatch(tok->previous(), "delete") || + Token::simpleMatch(tok->tokAt(-3), "delete [ ]")) + { + return tok; + } } if (Token::Match(tok, "%var% (")) diff --git a/test/testother.cpp b/test/testother.cpp index 6ab884356..1540460cf 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -959,6 +959,20 @@ private: "}\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); + checkUninitVar("static void foo()\n" + "{\n" + " int *p;\n" + " delete p;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); + + checkUninitVar("static void foo()\n" + "{\n" + " int *p;\n" + " delete [] p;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); + checkUninitVar("static void foo()\n" "{\n" " Foo p;\n"