From b55f6458a2a953eb502d86ca9079aef47bd1b895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 30 Oct 2010 12:32:43 +0200 Subject: [PATCH] Fixed #2120 (False positive: array index out of bounds (unknown type in struct, sub function)) --- lib/checkbufferoverrun.cpp | 2 +- test/testbufferoverrun.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 6ad4fff89..25be24834 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1804,7 +1804,7 @@ bool CheckBufferOverrun::ArrayInfo::declare(const Token *tok, const Tokenizer &t _element_size = 0; _varname.clear(); - if (!tok->isName()) + if (!tok->isName() || tok->str() == "return") return false; while (tok && (tok->str() == "static" || diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 8d6c4c5f9..b052ef21c 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -180,6 +180,7 @@ private: TEST_CASE(executionPaths1); TEST_CASE(executionPaths2); + TEST_CASE(executionPaths3); // no FP for function parameter TEST_CASE(cmdLineArgs1); @@ -2514,6 +2515,20 @@ private: ASSERT_EQUALS("", errout.str()); } + void executionPaths3() + { + epcheck("void f(char *VLtext)\n" + "{\n" + " if ( x ) {\n" + " return VLtext[0];\n" + " } else {\n" + " int wordlen = ab();\n" + " VLtext[wordlen] = 0;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void cmdLineArgs1() { check("int main(int argc, char* argv[])\n"