Skip to content

Commit a8df08f

Browse files
committed
Fixed #7659 (crash: Token::varId() : vxl: brdb_selection.cxx)
1 parent 3e509fb commit a8df08f

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

lib/checkstl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ void CheckStl::iterators()
168168
// inserting iterator range..
169169
if (tok2->strAt(2) == "insert") {
170170
const Token *par2 = itTok->nextArgument();
171-
while (par2 && par2->str() != ")") {
171+
if (!par2 || par2->nextArgument())
172+
continue;
173+
while (par2->str() != ")") {
172174
if (par2->varId() == container->declarationId())
173175
break;
174176
if (par2->str() == "(")

test/teststl.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,23 @@ class TestStl : public TestFixture {
209209
" l2.insert(it, l1.end());\n"
210210
"}");
211211
ASSERT_EQUALS("", errout.str());
212+
213+
// only warn for insert when there are preciself 2 arguments.
214+
check("void foo() {\n"
215+
" list<int> l1;\n"
216+
" list<int> l2;\n"
217+
" list<int>::iterator it = l1.begin();\n"
218+
" l2.insert(it);\n"
219+
"}");
220+
ASSERT_EQUALS("", errout.str());
221+
check("void foo() {\n"
222+
" list<int> l1;\n"
223+
" list<int> l2;\n"
224+
" list<int>::iterator it = l1.begin();\n"
225+
" l2.insert(it,0,1);\n"
226+
"}");
227+
ASSERT_EQUALS("", errout.str());
228+
212229
}
213230

214231
void iterator4() {

0 commit comments

Comments
 (0)