From e9bc72b4f2d0c0247c5e7d9ede33c94ccc41da2d Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 3 Jun 2011 22:16:08 -0400 Subject: [PATCH] todo tests for #2812 (false negative: null pointer dereference when returning struct member) --- test/testnullpointer.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 259fe8314..764879d65 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -45,6 +45,7 @@ private: TEST_CASE(nullpointer8); TEST_CASE(nullpointer9); TEST_CASE(nullpointer10); + TEST_CASE(nullpointer11); // ticket #2812 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 @@ -888,6 +889,16 @@ private: " p->x = 0;\n" "}\n"); ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str()); + } + + void nullpointer11() // ticket #2812 + { + check("int foo()\n" + "{\n" + " my_type* p = 0;\n" + " return p->x;\n" + "}\n"); + TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", "", errout.str()); check("int foo()\n" "{\n" @@ -896,6 +907,14 @@ private: "}\n"); TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", "", errout.str()); + check("int foo()\n" + "{\n" + " my_type* p;\n" + " p = 0; \n" + " return p->x;\n" + "}\n"); + TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", "", errout.str()); + check("int foo()\n" "{\n" " struct my_type* p;\n"