diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 687b1de10..3435549b5 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -55,6 +55,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list functionNames1_all; static std::set functionNames1_nullptr; + static std::set functionNames1_uninit; if (functionNames1_all.empty()) { // cstdlib functionNames1_all.insert("atoi"); @@ -106,7 +107,6 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::liststr() != "0") // Only if length (second parameter) is not zero var.push_back(firstParam); diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index d9ad68988..89d0057cc 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -52,6 +52,7 @@ private: TEST_CASE(nullpointer16); // #3591 TEST_CASE(nullpointer17); // #3567 TEST_CASE(nullpointer18); // #1927 + TEST_CASE(nullpointer19); // #3811 TEST_CASE(nullpointer_castToVoid); // #3771 TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it TEST_CASE(nullConstantDereference); // Dereference NULL constant @@ -1250,6 +1251,13 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Null pointer dereference\n", errout.str()); } + void nullpointer19() { // #3811 + check("int foo() {\n" + " perror(0);\n" + "}", true); + ASSERT_EQUALS("", errout.str()); + } + void nullpointer_castToVoid() { // #3771 check("void f () {\n" " int *buf = NULL;\n" diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 706d137e0..305716954 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1193,6 +1193,13 @@ private: "};\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str()); + checkUninitVar("void f()\n" + "{\n" + " char *s = malloc(100);\n" + " perror(s);\n" + "};"); + ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s\n", errout.str()); + checkUninitVar("void f()\n" "{\n" " char *s1 = new char[10];\n"