Fixed #10367 (False positive; pointer out of bounds argv-1)

This commit is contained in:
Daniel Marjamäki 2021-09-15 08:28:50 +02:00
parent 2d3b8d7003
commit a9a093e7cc
2 changed files with 8 additions and 0 deletions

View File

@ -486,6 +486,9 @@ void CheckBufferOverrun::pointerArithmetic()
if (const ValueFlow::Value *neg = indexToken->getValueLE(-1, mSettings))
pointerArithmeticError(tok, indexToken, neg);
} else if (tok->str() == "-") {
if (arrayToken->variable() && arrayToken->variable()->isArgument())
continue;
const Token *array = arrayToken;
while (Token::Match(array, ".|::"))
array = array->astOperand2();

View File

@ -3176,6 +3176,11 @@ private:
" dostuff(x-i);\n"
"}");
TODO_ASSERT_EQUALS("[test.cpp:4]: (portability) Undefined behaviour, when 'i' is -20 the pointer arithmetic 'x-i' is out of bounds.\n", "", errout.str());
check("void f(const char *x[10]) {\n"
" return x-4;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void strcat1() {