From 9ffb657c1a875e749dc565c81218d7ad750c28c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 20 Dec 2019 09:46:01 +0100 Subject: [PATCH] Fixed #8597 (False positive - Array index is used before limits check.) --- lib/checkbufferoverrun.cpp | 2 +- test/testbufferoverrun.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 235684124..dbefb03f3 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -633,7 +633,7 @@ void CheckBufferOverrun::arrayIndexThenCheck() // Iterate AST upwards const Token* tok2 = tok; const Token* tok3 = tok2; - while (tok2->astParent() && tok2->tokType() != Token::eLogicalOp) { + while (tok2->astParent() && tok2->tokType() != Token::eLogicalOp && tok2->str() != "?") { tok3 = tok2; tok2 = tok2->astParent(); } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 2c6c589be..459b44b0a 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -4099,6 +4099,11 @@ private: " sizeof(a)/sizeof(a[i]) && i < 10;\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("void f(int i) {\n" // ?: + " if ((i < 10 ? buf[i] : 1) && (i < 5 ? buf[i] : 5)){}\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void bufferNotZeroTerminated() {