Fixed #4035 (False positive: Memory leak: pTempFile)

This commit is contained in:
Daniel Marjamäki 2012-08-25 12:00:25 +02:00
parent 730935efdd
commit 985ac662ee
4 changed files with 30 additions and 34 deletions

View File

@ -1995,8 +1995,6 @@ bool Tokenizer::tokenize(std::istream &code,
removeRedundantSemicolons();
simplifyReservedWordNullptr();
simplifyParameterVoid();
simplifyRedundantConsecutiveBraces();
@ -2106,6 +2104,14 @@ void Tokenizer::simplifyNull()
tok->str("0");
}
}
// nullptr..
if (isCPP()) {
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (tok->str() == "nullptr")
tok->str("0");
}
}
}
void Tokenizer::concatenateNegativeNumber()
@ -2198,16 +2204,6 @@ void Tokenizer::simplifyParameterVoid()
}
}
void Tokenizer::simplifyReservedWordNullptr()
{
if (_settings->standards.cpp11) {
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (tok->str() == "nullptr")
tok->str("0");
}
}
}
void Tokenizer::simplifyRedundantConsecutiveBraces()
{
// Remove redundant consecutive braces, i.e. '.. { { .. } } ..' -> '.. { .. } ..'.

View File

@ -463,8 +463,6 @@ public:
bool hasComplicatedSyntaxErrorsInTemplates();
void simplifyReservedWordNullptr();
/**
* Simplify e.g. 'atol("0")' into '0'
*/

View File

@ -74,19 +74,18 @@ private:
TEST_CASE(crash1);
}
void check(const char code[], bool inconclusive = false, bool cpp11 = false) {
void check(const char code[], bool inconclusive = false, const char filename[] = "test.cpp") {
// Clear the error buffer..
errout.str("");
Settings settings;
settings.addEnabled("style");
settings.inconclusive = inconclusive;
settings.standards.cpp11 = cpp11;
// Tokenize..
Tokenizer tokenizer(&settings, this);
std::istringstream istr(code);
if (!tokenizer.tokenize(istr, "test.cpp"))
if (!tokenizer.tokenize(istr, filename))
return;
// Check for redundant code..
@ -1159,19 +1158,17 @@ private:
ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str());
}
void nullpointer12() { // ticket #2470
check("int foo()\n"
void nullpointer12() { // ticket #2470, #4035
const char code[] = "int foo()\n"
"{\n"
" int* i = nullptr;\n"
" return *i;\n"
"}\n", false, true); // Check as C++11 code
"}\n";
check(code, false, "test.cpp"); // C++ file => nullptr means NULL
ASSERT_EQUALS("[test.cpp:4]: (error) Null pointer dereference\n", errout.str());
check("int foo(int nullptr)\n"
"{\n"
" int* i = nullptr;\n"
" return *i;\n"
"}", true);
check(code, false, "test.c"); // C file => nullptr does not mean NULL
ASSERT_EQUALS("", errout.str());
}

View File

@ -4646,6 +4646,7 @@ private:
}
void simplify_null() {
{
const char code[] =
"int * p = NULL;\n"
"int * q = __null;\n";
@ -4654,6 +4655,10 @@ private:
ASSERT_EQUALS(expected, tokenizeAndStringify(code,true));
}
ASSERT_EQUALS("( a == nullptr )", tokenizeAndStringify("(a==nullptr)", false, false, Settings::Unspecified, "test.c"));
ASSERT_EQUALS("( ! a )", tokenizeAndStringify("(a==nullptr)", false, false, Settings::Unspecified, "test.cpp"));
}
void simplifyMulAndParens() {
// (error) Resource leak
const char code[] = "void f() {"