From 71c5d4bd60c77c6bc1c67332bf41d2a4739bd9db Mon Sep 17 00:00:00 2001 From: Frank Zingsheim Date: Tue, 21 Oct 2014 22:56:53 +0200 Subject: [PATCH] Ticket #6232 (cppOut of bounds array access) --HG-- extra : rebase_source : 79ed3533a12a486ea3ed3f09f9bc55b1a4771161 --- lib/checkbufferoverrun.cpp | 4 ++-- test/testbufferoverrun.cpp | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 3870f7f4f..10a234da2 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -698,8 +698,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vectorscope()->type == Scope::eGlobal) + // Declaration in global scope or namespace? + if (tok->scope()->type == Scope::eGlobal || tok->scope()->type == Scope::eNamespace) return; /* { diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 5bdec0bf0..3c3ad8577 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -2130,6 +2130,10 @@ private: check("class X { static const int x[100]; };\n" // #6070 "const int X::x[100] = {0};", false, "test.cpp", false); ASSERT_EQUALS("", errout.str()); + + check("namespace { class X { static const int x[100]; };\n" // #6232 + "const int X::x[100] = {0}; }", false, "test.cpp", false); + ASSERT_EQUALS("", errout.str()); } void buffer_overrun_1_posix_functions() {