Merge pull request #256 from xypron/5505

5505: FP: Array accessed out of bounds
This commit is contained in:
Daniel Marjamäki 2014-03-09 08:47:18 +01:00
commit 7fa73c0d64
2 changed files with 12 additions and 1 deletions

View File

@ -697,7 +697,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
// Check the parameter usage in the function scope..
for (const Token* ftok = func->functionScope->classStart; ftok != func->functionScope->classEnd; ftok = ftok->next()) {
if (Token::Match(ftok, "if|for|while (")) {
if (Token::Match(ftok, "if|for|switch|while (")) {
// bailout if there is buffer usage..
if (bailoutIfSwitch(ftok, parameter->declarationId())) {
break;

View File

@ -2776,6 +2776,17 @@ private:
" f(a);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(int a[]) {\n"
" switch (2) {\n"
" case 1:\n"
" a[1] = 1;\n"
" }\n"
"}\n"
"int a[1];\n"
"f(a);\n"
"");
ASSERT_EQUALS("", errout.str());
}
void possible_buffer_overrun_1() { // #3035