Fixed #4038 (FP: possible null pointer dereference)

This commit is contained in:
Daniel Marjamäki 2012-09-23 09:20:16 +02:00
parent 30100d32bd
commit c9c04f9691
2 changed files with 11 additions and 1 deletions

View File

@ -1268,7 +1268,6 @@ private:
return tok2; return tok2;
} }
} }
return tok2;
} }
return &tok; return &tok;

View File

@ -54,6 +54,7 @@ private:
TEST_CASE(nullpointer18); // #1927 TEST_CASE(nullpointer18); // #1927
TEST_CASE(nullpointer19); // #3811 TEST_CASE(nullpointer19); // #3811
TEST_CASE(nullpointer20); // #3807 (fp: return p ? (p->x() || p->y()) : z) TEST_CASE(nullpointer20); // #3807 (fp: return p ? (p->x() || p->y()) : z)
TEST_CASE(nullpointer21); // #4038 (fp: if (x) p=q; else return;)
TEST_CASE(nullpointer_castToVoid); // #3771 TEST_CASE(nullpointer_castToVoid); // #3771
TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it TEST_CASE(pointerCheckAndDeRef); // check if pointer is null and then dereference it
TEST_CASE(nullConstantDereference); // Dereference NULL constant TEST_CASE(nullConstantDereference); // Dereference NULL constant
@ -1280,6 +1281,16 @@ private:
TODO_ASSERT_EQUALS("error", "", errout.str()); TODO_ASSERT_EQUALS("error", "", errout.str());
} }
void nullpointer21() { // #4038 - fp: if (x) p=q; else return;
check("void f(int x) {\n"
" int *p = 0;\n"
" if (x) p = q;\n"
" else return;\n"
" *p = 0;\n" // <- p is not NULL
"}");
ASSERT_EQUALS("", errout.str());
}
void nullpointer_castToVoid() { // #3771 void nullpointer_castToVoid() { // #3771
check("void f () {\n" check("void f () {\n"
" int *buf = NULL;\n" " int *buf = NULL;\n"