diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 99c0ab1d8..21e6da6b3 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -245,7 +245,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::listvarId() > 0)) { + if ((value == 0 && Token::Match(secondParam, "0|NULL ,|)")) || (secondParam && secondParam->varId() > 0 && Token::Match(secondParam->next(),"[,)]"))) { if (functionNames2_all.find(tok.str()) != functionNames2_all.end()) var.push_back(secondParam); else if (value == 0 && functionNames2_nullptr.find(tok.str()) != functionNames2_nullptr.end()) @@ -302,7 +302,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::liststr() == "0") || (argListTok->varId() > 0)) { + if ((value == 0 && argListTok->str() == "0") || (argListTok->varId() > 0 && Token::Match(argListTok,"%var% [,)]"))) { var.push_back(argListTok); } } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 404082962..2d79491cf 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -1264,7 +1264,7 @@ private: " char cBuf[10];\n" " sprintf(cBuf, \"%s\", c ? c : \"0\" );\n" "}"); - TODO_ASSERT_EQUALS("","[test.cpp:4]: (error) Possible null pointer dereference: c\n", errout.str()); + ASSERT_EQUALS("",errout.str()); } void nullpointer24() { // #5083 - fp: chained assignment diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index af1189465..e761e02c0 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1240,6 +1240,12 @@ private: "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: a\n", errout.str()); + checkUninitVar("void f() {\n" // Ticket #5108 (fp) + " const char *a;\n" + " printf(\"%s\", a=\"abc\");\n" + "}"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("void f() {\n" // Ticket #3497 " char header[1];\n" " *((unsigned char*)(header)) = 0xff;\n"