Fix ticket #334 (segmentation fault on boost 1.39.0)

http://apps.sourceforge.net/trac/cppcheck/ticket/334
This commit is contained in:
Reijo Tomperi 2009-05-26 23:22:00 +03:00
parent 4f41adf45e
commit ea4232fb06
2 changed files with 21 additions and 4 deletions

View File

@ -104,12 +104,19 @@ void Token::deleteThis()
void Token::replace(Token *replaceThis, Token *start, Token *end)
{
// Fix the whole in the old location of start and end
start->previous()->next(end->next());
end->next()->previous(start->previous());
if (start->previous())
start->previous()->next(end->next());
if (end->next())
end->next()->previous(start->previous());
// Move start and end to their new location
replaceThis->previous()->next(start);
replaceThis->next()->previous(end);
if (replaceThis->previous())
replaceThis->previous()->next(start);
if (replaceThis->next())
replaceThis->next()->previous(end);
start->previous(replaceThis->previous());
end->next(replaceThis->next());

View File

@ -1735,6 +1735,16 @@ private:
ASSERT_EQUALS(false, tokenizer.tokenize(istr, "test.cpp"));
ASSERT_EQUALS(std::string("[test.cpp:1]: (error) Invalid number of character ((). Can't process file.\n"), errout.str());
}
{
errout.str("");
const char code[] = "namespace extract{\nB(weighted_moment)\n}\nusing extract::weighted_moment;\n";
Tokenizer tokenizer(s, this);
std::istringstream istr(code);
ASSERT_EQUALS(true, tokenizer.tokenize(istr, "test.cpp"));
tokenizer.simplifyTokenList();
ASSERT_EQUALS(std::string(""), errout.str());
}
}
};