Properly support "break" in CheckVaarg::va_list_usage() (#7533)

Ran AStyle
This commit is contained in:
PKEuS 2016-06-07 19:28:32 +02:00
parent 321d2aeafb
commit 53e2cabdbb
4 changed files with 61 additions and 9 deletions

View File

@ -122,9 +122,14 @@ void CheckVaarg::va_list_usage()
}
open = nopen;
tok = tok->linkAt(1);
} else if (Token::Match(tok, "throw|return|break"))
} else if (Token::Match(tok, "throw|return"))
exitOnEndOfStatement = true;
else if (_tokenizer->isCPP() && tok->str() == "try") {
else if (tok->str() == "break") {
const Scope* scope = tok->scope();
while (scope->nestedIn && scope->type != Scope::eFor && scope->type != Scope::eWhile && scope->type != Scope::eDo && scope->type != Scope::eSwitch)
scope = scope->nestedIn;
tok = scope->classEnd;
} else if (_tokenizer->isCPP() && tok->str() == "try") {
open = false;
break;
} else if (!open && tok->varId() == var->declarationId())

View File

@ -216,6 +216,53 @@ private:
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
// #7533
check("void action_push(int type, ...) {\n"
" va_list args;\n"
" va_start(args, type);\n"
" switch (push_mode) {\n"
" case UNDO:\n"
" list_add(&act->node, &to_redo);\n"
" break;\n"
" case REDO:\n"
" list_add(&act->node, &to_undo);\n"
" break;\n"
" }\n"
" va_end(args);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void action_push(int type, ...) {\n"
" va_list args;\n"
" va_start(args, type);\n"
" switch (push_mode) {\n"
" case UNDO:\n"
" list_add(&act->node, &to_redo);\n"
" va_end(args);\n"
" break;\n"
" case REDO:\n"
" list_add(&act->node, &to_undo);\n"
" va_end(args);\n"
" break;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void action_push(int type, ...) {\n"
" va_list args;\n"
" va_start(args, type);\n"
" switch (push_mode) {\n"
" case UNDO:\n"
" list_add(&act->node, &to_redo);\n"
" break;\n"
" case REDO:\n"
" list_add(&act->node, &to_undo);\n"
" va_end(args);\n"
" break;\n"
" }\n"
"}");
ASSERT_EQUALS("[test.cpp:13]: (error) va_list 'args' was opened but not closed by va_end().\n", errout.str());
}
void va_start_subsequentCalls() {