parent
79f091c59a
commit
0d72216cca
|
@ -318,6 +318,21 @@ void CheckBufferOverrun::arrayIndex()
|
|||
if (!getDimensionsEtc(tok->astOperand1(), mSettings, &dimensions, &errorPath, &mightBeLarger, &path))
|
||||
continue;
|
||||
|
||||
const Variable* const var = array->variable();
|
||||
if (var && var->isArgument() && var->scope()) {
|
||||
const Token* changeTok = var->scope()->bodyStart;
|
||||
bool isChanged = false;
|
||||
while ((changeTok = findVariableChanged(changeTok->next(), var->scope()->bodyEnd, /*indirect*/ 0, var->declarationId(),
|
||||
/*globalvar*/ false, mSettings, mTokenizer->isCPP()))) {
|
||||
if (!Token::simpleMatch(changeTok->astParent(), "[")) {
|
||||
isChanged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isChanged)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Positive index
|
||||
if (!mightBeLarger) { // TODO check arrays with dim 1 also
|
||||
const std::vector<ValueFlow::Value>& indexValues =
|
||||
|
|
|
@ -2641,7 +2641,13 @@ private:
|
|||
" a += 4;\n"
|
||||
" a[-1] = 0;\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("", "[test.cpp:3]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f(char a[10]) {\n"
|
||||
" a[0] = 0;\n"
|
||||
" a[-1] = 0;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Array 'a[10]' accessed at index -1, which is out of bounds.\n", errout.str());
|
||||
}
|
||||
|
||||
void array_index_enum_array() { // #8439
|
||||
|
|
Loading…
Reference in New Issue