This commit is contained in:
Sébastien Debrard 2011-01-23 16:32:41 +01:00
commit daef8ef5fd
6 changed files with 41 additions and 3 deletions

View File

@ -608,7 +608,7 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
}
}
if (Token::Match(tok2, "goto|return|continue|break|throw|if"))
if (Token::Match(tok2, "goto|return|continue|break|throw|if|switch"))
{
if (Token::Match(tok2, "return * %varid%", varid))
nullPointerError(tok2, tok->strAt(3));

View File

@ -217,11 +217,13 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
function.isPure = true;
// count the number of constructors
if (function.type == Function::eConstructor || function.type == Function::eCopyConstructor)
if (function.type == Function::eConstructor ||
function.type == Function::eCopyConstructor)
scope->numConstructors++;
// assume implementation is inline (definition and implementation same)
function.token = function.tokenDef;
function.arg = function.argDef;
// out of line function
if (Token::Match(end, ") const| ;") ||
@ -238,7 +240,6 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
{
function.isInline = true;
function.hasBody = true;
function.arg = function.argDef;
scope->functionList.push_back(function);
@ -831,6 +832,7 @@ void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok)
// syntax error?
if (!new_scope->classEnd)
{
(*scope)->nestedList.pop_back();
delete new_scope;
while (tok1->next())
tok1 = tok1->next();
@ -848,6 +850,7 @@ void SymbolDatabase::addNewFunction(Scope **scope, const Token **tok)
}
else
{
(*scope)->nestedList.pop_back();
delete new_scope;
*scope = NULL;
*tok = NULL;

View File

@ -2408,6 +2408,17 @@ bool Tokenizer::tokenize(std::istream &code,
// typedef..
simplifyTypedef();
// Fix internal error by updating links (#2376)
// TODO: Remove this "createLinks". Make sure that the testcase
// TestSimplifyTokens::simplifyTypedefFunction8
// doesn't fail.
if (!createLinks())
{
// Source has syntax errors, can't proceed
cppcheckError(0);
return false;
}
// enum..
simplifyEnum();

View File

@ -868,6 +868,19 @@ private:
" fred->a();\n"
"}");
ASSERT_EQUALS("", errout.str());
// #2493 - switch
check("void f(Fred *fred) {\n"
" if (fred == NULL) {\n"
" x = 0;\n"
" }\n"
" switch (x) {\n"
" case 1:\n"
" fred->a();\n"
" break;\n"
" };\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// Test CheckNullPointer::nullConstantDereference

View File

@ -243,6 +243,7 @@ private:
TEST_CASE(simplifyTypedefFunction5);
TEST_CASE(simplifyTypedefFunction6);
TEST_CASE(simplifyTypedefFunction7);
TEST_CASE(simplifyTypedefFunction8);
TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition)
@ -5440,6 +5441,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction8()
{
// #2376 - internal error
const char code[] = "typedef int f_expand(const nrv_byte *);\n"
"void f(f_expand *(*get_fexp(int))){}\n";
checkSimplifyTypedef(code);
ASSERT_EQUALS("", errout.str()); // make sure that there is no internal error
}
void reverseArraySyntax()
{
ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));

View File

@ -799,6 +799,7 @@ private:
" }\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: pItem\n", errout.str());
ASSERT_EQUALS("", errout.str()); // current result
}
// switch..