diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 849e150ff..ccd2fb3cf 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1561,6 +1561,9 @@ void CheckBufferOverrun::bufferOverrun() // char arr[10] = "123"; // arr[7] = 'x'; // warning: arr[7] is inside the array bounds, but past the string's end + if (tok->valueType() && tok->valueType()->type == ValueType::Type::CONTAINER) + continue; + const ArrayInfo arrayInfo(tok->varId(), varname, 1U, Token::getStrSize(strtoken)); valueFlowCheckArrayIndex(tok->next(), arrayInfo); } else { diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index 6d9bda351..0a0ddaafd 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -74,6 +74,8 @@ private: } void run() override { + LOAD_LIB_2(settings0.library, "std.cfg"); + settings0.addEnabled("warning"); settings0.addEnabled("style"); settings0.addEnabled("portability"); @@ -3124,6 +3126,14 @@ private: " s[10] = 0;\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("void foo()\n" // #7718 + "{\n" + " std::string s = \"123\";\n" + " s.resize(100);\n" + " s[10] = 0;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } // data is allocated with alloca