Fixed #4239 (segmentation fault of cppcheck (invalid code))

This commit is contained in:
Alexander Mai 2012-09-27 06:35:36 +02:00 committed by Daniel Marjamäki
parent b15cb09af6
commit 074b7781b2
2 changed files with 18 additions and 10 deletions

View File

@ -1016,17 +1016,19 @@ void Tokenizer::simplifyTypedef()
if (!func)
continue;
/** @todo add support for multi-token operators */
if (func->previous()->str() == "operator")
func = func->previous();
if (func->previous()) { // Ticket #4239
/** @todo add support for multi-token operators */
if (func->previous()->str() == "operator")
func = func->previous();
// check for qualifier
if (func->previous()->str() == "::") {
// check for available and matching class name
if (!spaceInfo.empty() && classLevel < spaceInfo.size() &&
func->strAt(-2) == spaceInfo[classLevel].className) {
memberScope = 0;
inMemberFunc = true;
// check for qualifier
if (func->previous()->str() == "::") {
// check for available and matching class name
if (!spaceInfo.empty() && classLevel < spaceInfo.size() &&
func->strAt(-2) == spaceInfo[classLevel].className) {
memberScope = 0;
inMemberFunc = true;
}
}
}
}

View File

@ -57,6 +57,7 @@ private:
TEST_CASE(tokenize22); // special marker $ from preprocessor
TEST_CASE(tokenize23); // tokenize "return - __LINE__;"
TEST_CASE(tokenize24); // #4195 (segmentation fault)
TEST_CASE(tokenize25); // #4239 (segmentation fault)
// don't freak out when the syntax is wrong
TEST_CASE(wrong_syntax1);
@ -651,6 +652,11 @@ private:
tokenizeAndStringify("enum { int f ( ) { return = } r = f ( ) ; }");
}
// #4239 - segfault for "f ( struct { int typedef T x ; } ) { }"
void tokenize25() {
tokenizeAndStringify("f ( struct { int typedef T x ; } ) { }");
}
void wrong_syntax1() {
{
const std::string code("TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))");