Merge branch 'master' of github.com:danmar/cppcheck

This commit is contained in:
Robert Reif 2011-08-07 16:49:07 -04:00
commit 403b508371
4 changed files with 32 additions and 0 deletions

View File

@ -1244,9 +1244,20 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
ArrayInfo arrayInfo(var, _tokenizer);
const Token *tok = var->nameToken();
while (tok && tok->str() != ";")
{
if (tok->str() == "{")
{
if (Token::simpleMatch(tok->previous(), "= {"))
tok = tok->link();
else
break;
}
tok = tok->next();
}
if (!tok)
break;
if (tok->str() == "{")
tok = tok->next();
checkScope(tok, arrayInfo);
}
}

View File

@ -665,6 +665,9 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
if (pointerVariables.find(varid) == pointerVariables.end())
continue;
if (Token::Match(vartok->next(), "&& ( %varid% =", varid))
continue;
// if this is true then it is known that the pointer is null
bool null = true;

View File

@ -442,6 +442,15 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
}
{
check("void foo(int a[10]) {\n"
" for (int i=0;i<50;++i) {\n"
" a[i] = 0;\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Buffer access out-of-bounds: a\n", errout.str());
}
}
void array_index_4()

View File

@ -1203,6 +1203,15 @@ private:
" *p = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 3\n", errout.str());
// check, assign and use
check("void f() {\n"
" char *p;\n"
" if (p == 0 && (p = malloc(10)) != 0) {\n"
" *p = 0;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
// Test CheckNullPointer::nullConstantDereference