Fixed #2130 (Invalid possible NULL pointer dereference, etc.)

This commit is contained in:
Daniel Marjamäki 2010-10-27 20:20:10 +02:00
parent fc98bcdcb2
commit 995e39200b
3 changed files with 20 additions and 7 deletions

View File

@ -2613,6 +2613,7 @@ void CheckOther::nullPointer()
nullPointerLinkedList();
nullPointerStructByDeRefAndChec();
nullPointerByDeRefAndChec();
nullPointerByCheckAndDeRef();
}
/** Derefencing null constant (simplified token list) */
@ -2948,7 +2949,7 @@ private:
{
while (tok)
{
if (tok->str() == "{" || tok->str() == "}")
if (Token::Match(tok, "{|}|return|goto|break|if"))
return;
const Token *next = parse(*tok, checks);
if (next)

View File

@ -89,9 +89,6 @@ public:
// New type of check: Check execution paths
checkOther.executionPaths();
checkOther.checkMisusedScopedObject();
// FIXME: I get a deadlock if I uncomment this:
checkOther.nullPointerByCheckAndDeRef();
}

View File

@ -613,9 +613,6 @@ private:
tokenizer.simplifyTokenList();
checkOther.nullConstantDereference();
checkOther.executionPaths();
tokenizer.simplifyTokenList();
checkOther.nullPointerByCheckAndDeRef();
}
@ -1125,6 +1122,17 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
checkNullPointer("void f(int a) {\n"
" const char *p = 0;\n"
" if (a) {\n"
" p = \"abcd\";\n"
" }\n"
" for (int i = 0; i < 3; i++) {\n"
" if (a && (p[i] == '1'));\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void nullpointer7()
@ -1204,6 +1212,13 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
// This is why this check can't be used on the simplified token list
checkNullPointer("void f(Foo *foo) {\n"
" if (!dynamic_cast<bar *>(foo)) {\n"
" *foo = 0;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void checkUninitVar(const char code[])