Skip to content

Commit a9a093e

Browse files
committed
Fixed #10367 (False positive; pointer out of bounds argv-1)
1 parent 2d3b8d7 commit a9a093e

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

lib/checkbufferoverrun.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ void CheckBufferOverrun::pointerArithmetic()
486486
if (const ValueFlow::Value *neg = indexToken->getValueLE(-1, mSettings))
487487
pointerArithmeticError(tok, indexToken, neg);
488488
} else if (tok->str() == "-") {
489+
if (arrayToken->variable() && arrayToken->variable()->isArgument())
490+
continue;
491+
489492
const Token *array = arrayToken;
490493
while (Token::Match(array, ".|::"))
491494
array = array->astOperand2();

test/testbufferoverrun.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,6 +3176,11 @@ class TestBufferOverrun : public TestFixture {
31763176
" dostuff(x-i);\n"
31773177
"}");
31783178
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());
3179+
3180+
check("void f(const char *x[10]) {\n"
3181+
" return x-4;\n"
3182+
"}");
3183+
ASSERT_EQUALS("", errout.str());
31793184
}
31803185

31813186
void strcat1() {

0 commit comments

Comments
 (0)