Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2280,8 +2280,11 @@ std::string Variable::getTypeName() const
{
std::string ret;
// TODO: For known types, generate the full type name
for (const Token *typeTok = mTypeStartToken; Token::Match(typeTok, "%name%|::") && typeTok->varId() == 0; typeTok = typeTok->next())
for (const Token *typeTok = mTypeStartToken; Token::Match(typeTok, "%name%|::") && typeTok->varId() == 0; typeTok = typeTok->next()) {
ret += typeTok->str();
if (Token::simpleMatch(typeTok->next(), "<") && typeTok->next()->link()) // skip template arguments
typeTok = typeTok->next()->link();
}
return ret;
}

Expand Down
13 changes: 13 additions & 0 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class TestBufferOverrun : public TestFixture {
TEST_CASE(array_index_negative4);
TEST_CASE(array_index_negative5); // #10526
TEST_CASE(array_index_negative6); // #11349
TEST_CASE(array_index_negative7); // #5685
TEST_CASE(array_index_for_decr);
TEST_CASE(array_index_varnames); // FP: struct member #1576, FN: #1586
TEST_CASE(array_index_for_continue); // for,continue
Expand Down Expand Up @@ -2255,6 +2256,18 @@ class TestBufferOverrun : public TestFixture {
ASSERT_EQUALS("", errout.str());
}

// #5685
void array_index_negative7()
{
check("void f() {\n"
" int i = -9;\n"
" int a[5];\n"
" for (; i < 5; i++)\n"
" a[i] = 1;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[5]' accessed at index -9, which is out of bounds.\n", errout.str());
}

void array_index_for_decr() {
check("void f()\n"
"{\n"
Expand Down
5 changes: 5 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6270,6 +6270,11 @@ class TestUnusedVar : public TestFixture {
" myManager.theDummyTable.addRow(UnsignedIndexValue{ myNewValue }, DummyRowData{ false });\n"
"}");
ASSERT_EQUALS("", errout.str());

functionVariableUsage("void f() {\n"
" std::list<std::list<int>>::value_type a{ 1, 2, 3, 4 };\n"
"}\n");
TODO_ASSERT_EQUALS("", "[test.cpp:2]: (information) --check-library: Provide <type-checks><unusedvar> configuration for std::list::value_type\n", errout.str());
}

void localvarRangeBasedFor() {
Expand Down