Skip to content

Commit a7086c5

Browse files
fixed #12378 FN containerOutOfBounds with scope operator / Library: cleaned up usage of Container::startPattern2 (#5908)
Co-authored-by: chrchr <christian.riesch@live.com>
1 parent ab93362 commit a7086c5

3 files changed

Lines changed: 36 additions & 29 deletions

File tree

lib/library.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,9 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
434434
const char* const startPattern = node->Attribute("startPattern");
435435
if (startPattern) {
436436
container.startPattern = startPattern;
437-
container.startPattern2 = container.startPattern + " !!::";
437+
container.startPattern2 = startPattern;
438+
if (!endsWith(container.startPattern, '<'))
439+
container.startPattern2 += " !!::";
438440
}
439441
const char* const endPattern = node->Attribute("endPattern");
440442
if (endPattern)

test/cfg/std.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4925,6 +4925,13 @@ std::string global_scope_std() // #12355
49254925
return ss.str();
49264926
}
49274927

4928+
::std::size_t global_scope_std2() // #12378
4929+
{
4930+
std::vector<::std::size_t> v;
4931+
// cppcheck-suppress containerOutOfBounds
4932+
return v.front();
4933+
}
4934+
49284935
void unique_lock_const_ref(std::mutex& m)
49294936
{
49304937
std::unique_lock lock(m);

test/testsymboldatabase.cpp

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8775,35 +8775,33 @@ class TestSymbolDatabase : public TestFixture {
87758775
}
87768776
{
87778777
// Container
8778-
Settings sC;
8779-
Library::Container c;
8780-
c.startPattern = "C";
8781-
c.startPattern2 = "C !!::";
8782-
sC.library.containers["C"] = c;
8778+
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
8779+
"<def>\n"
8780+
" <container id=\"C\" startPattern=\"C\"/>\n"
8781+
"</def>";
8782+
const Settings sC = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
87838783
ASSERT_EQUALS("container(C) *", typeOf("C*c=new C;","new","test.cpp",&sC));
87848784
ASSERT_EQUALS("container(C) *", typeOf("x=(C*)c;","(","test.cpp",&sC));
87858785
ASSERT_EQUALS("container(C)", typeOf("C c = C();","(","test.cpp",&sC));
87868786
}
87878787
{
87888788
// Container (vector)
8789-
Settings set;
8790-
Library::Container vector;
8791-
vector.startPattern = "Vector <";
8792-
vector.startPattern2 = "Vector !!::";
8793-
vector.type_templateArgNo = 0;
8794-
vector.arrayLike_indexOp = true;
8795-
vector.functions["front"] =
8796-
Library::Container::Function{Library::Container::Action::NO_ACTION, Library::Container::Yield::ITEM};
8797-
vector.functions["data"] =
8798-
Library::Container::Function{Library::Container::Action::NO_ACTION, Library::Container::Yield::BUFFER};
8799-
vector.functions["begin"] = Library::Container::Function{Library::Container::Action::NO_ACTION,
8800-
Library::Container::Yield::START_ITERATOR};
8801-
set.library.containers["Vector"] = vector;
8802-
Library::Container string;
8803-
string.startPattern = "test :: string";
8804-
string.startPattern2 = "test :: string !!::";
8805-
string.arrayLike_indexOp = string.stdStringLike = true;
8806-
set.library.containers["test::string"] = string;
8789+
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
8790+
"<def>\n"
8791+
" <container id=\"Vector\" startPattern=\"Vector &lt;\">\n"
8792+
" <type templateParameter=\"0\"/>\n"
8793+
" <access indexOperator=\"array-like\">\n"
8794+
" <function name=\"front\" yields=\"item\"/>\n"
8795+
" <function name=\"data\" yields=\"buffer\"/>\n"
8796+
" <function name=\"begin\" yields=\"start-iterator\"/>\n"
8797+
" </access>\n"
8798+
" </container>\n"
8799+
" <container id=\"test::string\" startPattern=\"test :: string\">\n"
8800+
" <type string=\"std-like\"/>\n"
8801+
" <access indexOperator=\"array-like\"/>\n"
8802+
" </container>\n"
8803+
"</def>";
8804+
const Settings set = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
88078805
ASSERT_EQUALS("signed int", typeOf("Vector<int> v; v[0]=3;", "[", "test.cpp", &set));
88088806
ASSERT_EQUALS("container(test :: string)", typeOf("{return test::string();}", "(", "test.cpp", &set));
88098807
ASSERT_EQUALS(
@@ -8876,11 +8874,11 @@ class TestSymbolDatabase : public TestFixture {
88768874
// return
88778875
{
88788876
// Container
8879-
Settings sC;
8880-
Library::Container c;
8881-
c.startPattern = "C";
8882-
c.startPattern2 = "C !!::";
8883-
sC.library.containers["C"] = c;
8877+
constexpr char xmldata[] = "<?xml version=\"1.0\"?>\n"
8878+
"<def>\n"
8879+
" <container id=\"C\" startPattern=\"C\"/>\n"
8880+
"</def>";
8881+
const Settings sC = settingsBuilder().libraryxml(xmldata, sizeof(xmldata)).build();
88848882
ASSERT_EQUALS("container(C)", typeOf("C f(char *p) { char data[10]; return data; }", "return", "test.cpp", &sC));
88858883
}
88868884
// Smart pointer

0 commit comments

Comments
 (0)