From 0bddd1977f087c446e04ba680d1090ab1b4d3a3a Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 29 Mar 2010 17:25:38 +0200 Subject: [PATCH] Fixed #1536 (###### If you see this, there is a bug ###### Token::Match() - varid was 0) --- lib/checkbufferoverrun.cpp | 4 ++++ test/testbufferoverrun.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+) 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"