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"