diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 4cc2a53ae..4492d5100 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -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(); diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 1a1e8aaf0..3113d99a5 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -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() {