From fd153eac02450ba591925db1c99f553ac06be1a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 27 Oct 2010 19:38:42 +0200 Subject: [PATCH] Fixed #2142 (false positive: null pointer dereference (throw)) --- lib/checkother.cpp | 2 +- test/testother.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index c43ac0141..8b1034df5 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2562,7 +2562,7 @@ void CheckOther::nullPointerByCheckAndDeRef() } } - if (Token::Match(tok2, "goto|return|continue|break|if")) + if (Token::Match(tok2, "goto|return|continue|break|throw|if")) { if (Token::Match(tok2, "return * %var%")) nullPointerError(tok2, tok->strAt(3)); diff --git a/test/testother.cpp b/test/testother.cpp index cb89c5ff5..a8db87a25 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1189,6 +1189,14 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkNullPointer("void foo(char *p) {\n" + " if (!p) {\n" + " throw x;\n" + " }\n" + " *p = 0;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } void checkUninitVar(const char code[])