Fixed crash caused by endless recursion in redundant assignments check

This commit is contained in:
Daniel Marjamäki 2013-11-10 17:20:40 +01:00
parent ff4cf68338
commit 807f62520c
2 changed files with 13 additions and 5 deletions

View File

@ -622,15 +622,11 @@ static void eraseNotLocalArg(std::map<unsigned int, const Token*>& container, co
static void eraseMemberAssignments(const unsigned int varId, std::map<unsigned int, std::set<unsigned int> > &membervars, std::map<unsigned int, const Token*> &varAssignments)
{
if (varAssignments.empty() || membervars.empty())
return;
const std::map<unsigned int, std::set<unsigned int> >::const_iterator it = membervars.find(varId);
if (it != membervars.end()) {
const std::set<unsigned int> &v = it->second;
for (std::set<unsigned int>::const_iterator vit = v.begin(); vit != v.end(); ++vit) {
for (std::set<unsigned int>::const_iterator vit = v.begin(); vit != v.end(); ++vit)
varAssignments.erase(*vit);
eraseMemberAssignments(*vit, membervars, varAssignments);
}
}
}

View File

@ -6392,6 +6392,18 @@ private:
" ab->b = 2;\n"
"}");
ASSERT_EQUALS("", errout.str());
// don't crash
check("struct data {\n"
" struct { int i; } fc;\n"
"};\n"
"struct state {\n"
" struct data d[123];\n"
"};\n"
"void func(struct state *s) {\n"
" s->foo[s->x++] = 2;\n"
" s->d[1].fc.i++;\n"
"}");
}
void redundantMemWrite() {