From 083954049fd1246596f29914b882397da92aecc7 Mon Sep 17 00:00:00 2001 From: Ettl Martin Date: Sun, 1 Apr 2012 15:54:41 +0200 Subject: [PATCH] #1927 added testcase. --- test/testnullpointer.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 53c63f66c..38f74e1e5 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -51,6 +51,7 @@ private: TEST_CASE(nullpointer15); // #3560 (fp: return p ? f(*p) : f(0)) TEST_CASE(nullpointer16); // #3591 TEST_CASE(nullpointer17); // #3567 + TEST_CASE(nullpointer18); // #1927 TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it TEST_CASE(nullConstantDereference); // Dereference NULL constant TEST_CASE(gcc_statement_expression); // Don't crash @@ -1226,6 +1227,20 @@ private: ASSERT_EQUALS("", errout.str()); } + void nullpointer18() { // #1927 + check("void f ()\n" + "{\n" + " int i=0;\n" + " char *str=NULL;\n" + " while (str[i])\n" + " {\n" + " i++;\n" + " };\n" + "}\n" + ); + ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference\n", errout.str()); + } + // Check if pointer is null and the dereference it void pointerCheckAndDeRef() { check("void foo(char *p) {\n"