Skip to content

Commit 659cd96

Browse files
committed
Fixed danmar#7209 (False positive: Array index used before limits check reported in sizeof)
1 parent 6faa637 commit 659cd96

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/checkbufferoverrun.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,11 @@ void CheckBufferOverrun::arrayIndexThenCheck()
18031803
for (std::size_t i = 0; i < functions; ++i) {
18041804
const Scope * const scope = symbolDatabase->functionScopes[i];
18051805
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
1806+
if (Token::simpleMatch(tok, "sizeof (")) {
1807+
tok = tok->linkAt(1);
1808+
continue;
1809+
}
1810+
18061811
if (Token::Match(tok, "%name% [ %var% ]")) {
18071812
tok = tok->tokAt(2);
18081813

test/testbufferoverrun.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,6 +3801,11 @@ class TestBufferOverrun : public TestFixture {
38013801
" }\n"
38023802
"}");
38033803
TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", "", errout.str());
3804+
3805+
check("void f(int i) {\n" // sizeof
3806+
" sizeof(a)/sizeof(a[i]) && i < 10;\n"
3807+
"}");
3808+
ASSERT_EQUALS("", errout.str());
38043809
}
38053810

38063811
void bufferNotZeroTerminated() {

0 commit comments

Comments
 (0)