Fix #9130 (FP memory leak with NULL pointer cast) (#1839)

This commit is contained in:
Rikard Falkeborn 2019-05-18 06:22:25 +02:00 committed by Daniel Marjamäki
parent cf3515ee61
commit ada881ccdf
2 changed files with 12 additions and 1 deletions

View File

@ -131,7 +131,7 @@ static bool match(const Token *tok, const std::string &rhs)
{
if (tok->str() == rhs)
return true;
if (tok->isName() && !tok->varId() && tok->hasKnownIntValue() && MathLib::toString(tok->values().front().intvalue) == rhs)
if (!tok->varId() && tok->hasKnownIntValue() && MathLib::toString(tok->values().front().intvalue) == rhs)
return true;
return false;
}

View File

@ -104,6 +104,7 @@ private:
TEST_CASE(ifelse11); // #8365 - if (NULL == (p = malloc(4)))
TEST_CASE(ifelse12); // #8340 - if ((*p = malloc(4)) == NULL)
TEST_CASE(ifelse13); // #8392
TEST_CASE(ifelse14); // #9130 - if (x == (char*)NULL)
// switch
TEST_CASE(switch1);
@ -1203,6 +1204,16 @@ private:
TODO_ASSERT_EQUALS("[test.cpp:4] memory leak", "", errout.str());
}
void ifelse14() { // #9130
check("char* f() {\n"
" char* buf = malloc(10);\n"
" if (buf == (char*)NULL)\n"
" return NULL;\n"
" return buf;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void switch1() {
check("void f() {\n"
" char *p = 0;\n"