From f1faaac1f23c634305790b6cd8a82ddd4097511e Mon Sep 17 00:00:00 2001 From: Ettl Martin Date: Sun, 9 Sep 2012 19:49:40 +0200 Subject: [PATCH] Added testcases for #3098 --- test/testuninitvar.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 36646a2cf..903becd51 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -842,6 +842,39 @@ private: " { }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // Ticket #3098 - False negative uninitialized variable + checkUninitVar("void f()\n" + "{\n" + " char *c1,*c2;\n" + " if(strcoll(c1,c2))\n" + " {\n" + " }\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c1\n" + "[test.cpp:4]: (error) Uninitialized variable: c2\n", errout.str()); + + checkUninitVar("void f(char *c1, char *c2)\n" + "{\n" + " if(strcoll(c1,c2))\n" + " {\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + checkUninitVar("void f()\n" + "{\n" + " char *c1;\n" + " c1=strcpy(c1,\"test\");\n" + "}\n"); + TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: c1\n","", errout.str()); + + checkUninitVar("void f(char *c1)\n" + "{\n" + " c1=strcpy(c1,\"test\");\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + }