diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 9ec9b1c24..a3f8f2a51 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -816,6 +816,10 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() if (tok->next()->str() == "*") ++varpos; + // make sure the variable is defined + if (tok->tokAt(varpos + 2)->varId() == 0) + continue; // FIXME we loose the check for negative index when we bail + // get maximum size from type // find where this token is defined const Token *index_type = Token::findmatch(_tokenizer->tokens(), "%varid%", tok->tokAt(varpos + 2)->varId()); diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 90d4f9ebb..78ad0b764 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -94,6 +94,7 @@ private: TEST_CASE(array_index_22); TEST_CASE(array_index_23); TEST_CASE(array_index_24); // ticket #1492 + TEST_CASE(array_index_25); // ticket #1536 TEST_CASE(array_index_multidim); TEST_CASE(array_index_switch_in_for); TEST_CASE(array_index_calculation); @@ -794,6 +795,16 @@ private: "[test.cpp:4]: (error) Array 'a[65536]' index 65536 out of bounds\n", errout.str()); } + void array_index_25() + { + // ticket #1536 + check("void foo()\n" + "{\n" + " long l[SOME_SIZE];\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void array_index_multidim() { check("void f()\n"