diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index bc865936c..1d07138c8 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1803,6 +1803,11 @@ void CheckBufferOverrun::arrayIndexThenCheck() for (std::size_t i = 0; i < functions; ++i) { const Scope * const scope = symbolDatabase->functionScopes[i]; for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { + if (Token::simpleMatch(tok, "sizeof (")) { + tok = tok->linkAt(1); + continue; + } + if (Token::Match(tok, "%name% [ %var% ]")) { tok = tok->tokAt(2); diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index f9c05ae63..8c7e1a288 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -3801,6 +3801,11 @@ private: " }\n" "}"); TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", "", errout.str()); + + check("void f(int i) {\n" // sizeof + " sizeof(a)/sizeof(a[i]) && i < 10;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void bufferNotZeroTerminated() {