diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 93d3d890b..fb16deb9a 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1244,9 +1244,20 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() ArrayInfo arrayInfo(var, _tokenizer); const Token *tok = var->nameToken(); while (tok && tok->str() != ";") + { + if (tok->str() == "{") + { + if (Token::simpleMatch(tok->previous(), "= {")) + tok = tok->link(); + else + break; + } tok = tok->next(); + } if (!tok) break; + if (tok->str() == "{") + tok = tok->next(); checkScope(tok, arrayInfo); } } diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index dc6f5cf90..1518ee522 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -442,6 +442,15 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); } + + { + check("void foo(int a[10]) {\n" + " for (int i=0;i<50;++i) {\n" + " a[i] = 0;\n" + " }\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (error) Buffer access out-of-bounds: a\n", errout.str()); + } } void array_index_4()