diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 5669f506c..3e53906ac 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -883,7 +883,7 @@ void CheckNullPointer::nullConstantDereference() else if (Token::simpleMatch(tok->previous(), ">> 0")) { // Only checking input stream operations is safe here, because otherwise 0 can be an integer as well const Token* tok2 = tok->previous(); // Find start of statement for (; tok2; tok2 = tok2->previous()) { - if (Token::Match(tok2->previous(), ";|{|}|:")) + if (Token::Match(tok2->previous(), ";|{|}|:|(")) break; } if (Token::simpleMatch(tok2, "std :: cin")) @@ -1064,4 +1064,3 @@ void CheckNullPointer::nullPointerDefaultArgError(const Token *tok, const std::s { reportError(tok, Severity::warning, "nullPointer", "Possible null pointer dereference if the default parameter value is used: " + varname); } - diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index b69afe1cb..58d09cb95 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -2132,6 +2132,15 @@ private: " std::cout << i;\n" // Its no char* (#4240) "}", true); ASSERT_EQUALS("", errout.str()); + + // #5811 false postive: (error) Null pointer dereference + check("using namespace std;\n" + "std::string itoip(int ip) {\n" + " stringstream out;\n" + " out << ((ip >> 0) & 0xFF);\n" + " return out.str();\n" + "}n", true, "test.cpp", false); + ASSERT_EQUALS("", errout.str()); } void functioncall() { // #3443 - function calls