From 1677e2913ed859e052e2a2acadb594f2468f0053 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Wed, 26 Mar 2014 12:17:27 +0100 Subject: [PATCH] Regression test for #5061. --- test/testnullpointer.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 5bfc80eb0..b171b8b30 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -58,6 +58,7 @@ private: TEST_CASE(nullpointer21); // #4038 (fp: if (x) p=q; else return;) TEST_CASE(nullpointer23); // #4665 (false positive) TEST_CASE(nullpointer24); // #5082 fp: chained assignment + TEST_CASE(nullpointer25); // #5061 TEST_CASE(nullpointer_cast); // #4692 TEST_CASE(nullpointer_castToVoid); // #3771 TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it @@ -1281,6 +1282,16 @@ private: ASSERT_EQUALS("", errout.str()); } + void nullpointer25() { // #5061 + check("void f(int *data, int i)\n" + "{\n" + " int *array = NULL;\n" + " if (data == 1 && array[i] == 0)\n" + " std::cout << \"test\";\n" + "}"); + ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: array\n", errout.str()); + } + void nullpointer_cast() { // #4692 check("char *nasm_skip_spaces(const char *p) {\n" " if (p)\n"