From 7f2ca357b01cb63128520b85fa40f1ad07514bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 19 Sep 2009 10:54:10 +0200 Subject: [PATCH] Fixed #673 (False positive: null pointer dereference when dynamic cast is used) --- src/checkother.h | 2 +- src/tokenize.cpp | 2 ++ test/testother.cpp | 11 +++++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/checkother.h b/src/checkother.h index 48ed50349..f75ac02e9 100644 --- a/src/checkother.h +++ b/src/checkother.h @@ -52,6 +52,7 @@ public: checkOther.warningOldStylePointerCast(); checkOther.checkUnsignedDivision(); checkOther.checkCharVariable(); + checkOther.nullPointer(); } } @@ -75,7 +76,6 @@ public: checkOther.strPlusChar(); checkOther.invalidFunctionUsage(); - checkOther.nullPointer(); checkOther.checkZeroDivision(); } diff --git a/src/tokenize.cpp b/src/tokenize.cpp index cb66adf99..ed1041a37 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -499,6 +499,8 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[]) } } + setVarId(); + return true; } //--------------------------------------------------------------------------- diff --git a/test/testother.cpp b/test/testother.cpp index 4a8e41ecd..7a116b4e5 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -519,8 +519,6 @@ private: Tokenizer tokenizer; std::istringstream istr(code); tokenizer.tokenize(istr, "test.cpp"); - tokenizer.simplifyTokenList(); - tokenizer.setVarId(); // Clear the error buffer.. errout.str(""); @@ -669,6 +667,15 @@ private: " while (a > 0);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // dynamic_cast.. + checkNullPointer("void foo(ABC *abc)\n" + "{\n" + " int a = abc->a;\n" + " if (!dynamic_cast(abc))\n" + " ;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } // Dereferencing a pointer and then checking if it is null