Fixed #7104 (False positive arrayIndexOutOfBounds)

This commit is contained in:
Daniel Marjamäki 2015-11-08 09:30:23 +01:00
parent fdb596fa05
commit 7d6e1974eb
2 changed files with 8 additions and 1 deletions

View File

@ -1089,7 +1089,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
if (!it->tokvalue)
continue;
const Variable *var = it->tokvalue->variable();
if (var && var->isArray() && var->dimensions().size() == 1U && value->intvalue > var->dimension(0)) {
if (var && var->isArray() && var->dimensions().size() == 1U && var->dimensionKnown(0) && value->intvalue > var->dimension(0)) {
std::list<const Token *> callstack;
callstack.push_back(it->tokvalue);
callstack.push_back(tok);

View File

@ -2065,6 +2065,13 @@ private:
" p[20] = 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (error) Array 'a[10]' accessed at index 20, which is out of bounds.\n", errout.str());
check("void f() {\n"
" int a[X];\n"
" int *p = a;\n"
" p[20] = 0;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void array_index_function_parameter() {