Fix #903 (false positive: buffer access out of bounds)

http://sourceforge.net/apps/trac/cppcheck/ticket/903
This commit is contained in:
Reijo Tomperi 2009-11-07 00:58:33 +02:00
parent 77b676937d
commit b222ef89be
2 changed files with 15 additions and 0 deletions

View File

@ -668,6 +668,9 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
continue;
}
if (varid == 0)
continue;
Token sizeTok;
sizeTok.str(type);
int total_size = size * _tokenizer->sizeOfType(&sizeTok);

View File

@ -296,6 +296,18 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:6]: (error) Buffer access out-of-bounds\n", errout.str());
}
{
check("typedef struct g g2[3];\n"
"void foo(char *a)\n"
"{\n"
" for (int i = 0; i < 4; i++)\n"
" {\n"
" a[i]=0;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
}