Fixed #673 (False positive: null pointer dereference when dynamic cast is used)

This commit is contained in:
Daniel Marjamäki 2009-09-19 10:54:10 +02:00
parent 4c30ab0b88
commit 7f2ca357b0
3 changed files with 12 additions and 3 deletions

View File

@ -52,6 +52,7 @@ public:
checkOther.warningOldStylePointerCast(); checkOther.warningOldStylePointerCast();
checkOther.checkUnsignedDivision(); checkOther.checkUnsignedDivision();
checkOther.checkCharVariable(); checkOther.checkCharVariable();
checkOther.nullPointer();
} }
} }
@ -75,7 +76,6 @@ public:
checkOther.strPlusChar(); checkOther.strPlusChar();
checkOther.invalidFunctionUsage(); checkOther.invalidFunctionUsage();
checkOther.nullPointer();
checkOther.checkZeroDivision(); checkOther.checkZeroDivision();
} }

View File

@ -499,6 +499,8 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
} }
} }
setVarId();
return true; return true;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -519,8 +519,6 @@ private:
Tokenizer tokenizer; Tokenizer tokenizer;
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, "test.cpp"); tokenizer.tokenize(istr, "test.cpp");
tokenizer.simplifyTokenList();
tokenizer.setVarId();
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");
@ -669,6 +667,15 @@ private:
" while (a > 0);\n" " while (a > 0);\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// dynamic_cast..
checkNullPointer("void foo(ABC *abc)\n"
"{\n"
" int a = abc->a;\n"
" if (!dynamic_cast<DEF *>(abc))\n"
" ;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
// Dereferencing a pointer and then checking if it is null // Dereferencing a pointer and then checking if it is null