#5811 false postive: (error) Null pointer dereference

This commit is contained in:
Alexander Mai 2014-05-17 18:18:20 +02:00
parent e04351ec33
commit 9dce9bddcb
2 changed files with 10 additions and 2 deletions

View File

@ -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 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 const Token* tok2 = tok->previous(); // Find start of statement
for (; tok2; tok2 = tok2->previous()) { for (; tok2; tok2 = tok2->previous()) {
if (Token::Match(tok2->previous(), ";|{|}|:")) if (Token::Match(tok2->previous(), ";|{|}|:|("))
break; break;
} }
if (Token::simpleMatch(tok2, "std :: cin")) 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); reportError(tok, Severity::warning, "nullPointer", "Possible null pointer dereference if the default parameter value is used: " + varname);
} }

View File

@ -2132,6 +2132,15 @@ private:
" std::cout << i;\n" // Its no char* (#4240) " std::cout << i;\n" // Its no char* (#4240)
"}", true); "}", true);
ASSERT_EQUALS("", errout.str()); 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 void functioncall() { // #3443 - function calls