Skip to content

Commit 9ffb657

Browse files
committed
Fixed #8597 (False positive - Array index is used before limits check.)
1 parent 02eaf6f commit 9ffb657

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/checkbufferoverrun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ void CheckBufferOverrun::arrayIndexThenCheck()
633633
// Iterate AST upwards
634634
const Token* tok2 = tok;
635635
const Token* tok3 = tok2;
636-
while (tok2->astParent() && tok2->tokType() != Token::eLogicalOp) {
636+
while (tok2->astParent() && tok2->tokType() != Token::eLogicalOp && tok2->str() != "?") {
637637
tok3 = tok2;
638638
tok2 = tok2->astParent();
639639
}

test/testbufferoverrun.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4099,6 +4099,11 @@ class TestBufferOverrun : public TestFixture {
40994099
" sizeof(a)/sizeof(a[i]) && i < 10;\n"
41004100
"}");
41014101
ASSERT_EQUALS("", errout.str());
4102+
4103+
check("void f(int i) {\n" // ?:
4104+
" if ((i < 10 ? buf[i] : 1) && (i < 5 ? buf[i] : 5)){}\n"
4105+
"}");
4106+
ASSERT_EQUALS("", errout.str());
41024107
}
41034108

41044109
void bufferNotZeroTerminated() {

0 commit comments

Comments
 (0)