Fixed ticket #3310 (segmentation fault of cppcheck)

This commit is contained in:
Edoardo Prezioso 2011-11-08 17:37:24 +01:00
parent 3abece027e
commit a546fc6e9d
2 changed files with 21 additions and 6 deletions

View File

@ -4170,7 +4170,7 @@ bool Tokenizer::simplifyTokenList()
}
}
/* // Replace "&str[num]" => "(str + num)"
// Replace "&str[num]" => "(str + num)"
//TODO: fix the fails testrunner reports:
//1)
//test/teststl.cpp:805: Assertion failed.
@ -4184,7 +4184,7 @@ bool Tokenizer::simplifyTokenList()
//"[test.cpp:4]: (error) Return of the address of an auto-variable\n".
//Actual:
//"".
for (Token *tok = _tokens; tok; tok = tok->next()) {
/*for (Token *tok = _tokens; tok; tok = tok->next()) {
if ((Token::Match(tok->next(), "& %var% [ %num% ]") ||
Token::Match(tok->next(), "& %var% [ %var% ]"))) {
tok = tok->next();
@ -9674,13 +9674,17 @@ void Tokenizer::removeUnnecessaryQualification()
}
while (tok1 && tok1->str() != "(") {
if (tok1->str() == ";")
break;
tok1 = tok1->next();
++offset;
}
if (!tok1 || tok1->str() != "(")
continue;
} else if (tok->strAt(2) == "~")
++offset;
if (Token::Match(tok->tokAt(offset)->link(), ") const| {|;|:")) {
if (tok->tokAt(offset) && Token::Match(tok->tokAt(offset)->link(), ") const| {|;|:")) {
std::string qualification = tok->str() + "::";
// check for extra qualification

View File

@ -382,10 +382,11 @@ private:
TEST_CASE(removeUnnecessaryQualification3);
TEST_CASE(removeUnnecessaryQualification4);
TEST_CASE(removeUnnecessaryQualification5);
TEST_CASE(removeUnnecessaryQualification6); // ticket #2859
TEST_CASE(removeUnnecessaryQualification7); // ticket #2970
TEST_CASE(removeUnnecessaryQualification6); // ticket #2859
TEST_CASE(removeUnnecessaryQualification7); // ticket #2970
TEST_CASE(removeUnnecessaryQualification8);
TEST_CASE(removeUnnecessaryQualification9); // ticket #3151
TEST_CASE(removeUnnecessaryQualification9); // ticket #3151
TEST_CASE(removeUnnecessaryQualification10); // ticket #3310 segmentation fault
TEST_CASE(simplifyIfNotNull);
TEST_CASE(simplifyVarDecl1); // ticket # 2682 segmentation fault
@ -7420,6 +7421,16 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (portability) Extra qualification 'Fred::' unnecessary and considered an error by many compilers.\n", errout.str());
}
void removeUnnecessaryQualification10() {
const char code[] = "template<typename T> class A\n"
"{\n"
" operator T();\n"
" A() { T (A::*f)() = &A::operator T; }\n"
"};\n";
tok(code, false);
ASSERT_EQUALS("", errout.str());
}
void simplifyIfNotNull() {
{
// ticket # 2601 segmentation fault