Fixed ticket #3482 (segmentation fault of cppcheck ( switch(){case} ))
This commit is contained in:
parent
57fcde8090
commit
54f54761b4
|
@ -2694,20 +2694,31 @@ void Tokenizer::arraySize()
|
|||
|
||||
void Tokenizer::simplifyLabelsCaseDefault()
|
||||
{
|
||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||
if (Token::Match(tok, ") const| {")) {
|
||||
// Simplify labels in the executable scope..
|
||||
bool executablescope = false;
|
||||
unsigned int indentlevel = 0;
|
||||
while (NULL != (tok = tok->next())) {
|
||||
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||
// Simplify labels in the executable scope..
|
||||
if (Token::Match(tok, ") const| {")) {
|
||||
tok = tok->next();
|
||||
if (tok->str() == "const")
|
||||
tok = tok->next();
|
||||
executablescope = true;
|
||||
}
|
||||
|
||||
if (!executablescope)
|
||||
continue;
|
||||
|
||||
if (tok->str() == "{") {
|
||||
if (tok->previous() && tok->previous()->str() == "=")
|
||||
if (tok->previous()->str() == "=")
|
||||
tok = tok->link();
|
||||
else
|
||||
++indentlevel;
|
||||
} else if (tok->str() == "}") {
|
||||
--indentlevel;
|
||||
if (!indentlevel)
|
||||
break;
|
||||
if (!indentlevel) {
|
||||
executablescope = false;
|
||||
continue;
|
||||
}
|
||||
} else if (tok->str() == "(" || tok->str() == "[")
|
||||
tok = tok->link();
|
||||
|
||||
|
@ -2716,7 +2727,10 @@ void Tokenizer::simplifyLabelsCaseDefault()
|
|||
if (tok->str() == ":")
|
||||
break;
|
||||
}
|
||||
if (Token::Match(tok, ": !!;")) {
|
||||
if (!tok)
|
||||
break;
|
||||
else if (tok->str() == ":" &&
|
||||
(!tok->next() || tok->next()->str() != ";")) {
|
||||
tok->insertToken(";");
|
||||
}
|
||||
} else if (Token::Match(tok, "[;{}] %var% : !!;")) {
|
||||
|
@ -2724,8 +2738,6 @@ void Tokenizer::simplifyLabelsCaseDefault()
|
|||
tok->insertToken(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5239,6 +5239,8 @@ private:
|
|||
//with unhandled MACRO() code
|
||||
ASSERT_EQUALS(" void f(){ MACRO( ab: b=0;, foo)}", labels_("void f() { MACRO(ab: b=0;, foo)}"));
|
||||
ASSERT_EQUALS(" void f(){ MACRO( bar, ab:{&(* b. x)=0;})}", labels_("void f() { MACRO(bar, ab: {&(*b.x)=0;})}"));
|
||||
//don't crash with garbage code
|
||||
ASSERT_EQUALS(" switch(){ case}", labels_("switch(){case}"));
|
||||
}
|
||||
|
||||
// Check simplifyInitVar
|
||||
|
|
Loading…
Reference in New Issue