CheckVaarg::va_list_usage(): Bailout when try{} block is encountered (#6186)

This commit is contained in:
PKEuS 2014-09-27 11:03:58 +02:00
parent 21c85118d6
commit 812bc6bdaf
2 changed files with 16 additions and 1 deletions

View File

@ -114,7 +114,10 @@ void CheckVaarg::va_list_usage()
tok = tok->linkAt(1); tok = tok->linkAt(1);
} else if (Token::Match(tok, "throw|return")) } else if (Token::Match(tok, "throw|return"))
exitOnEndOfStatement = true; exitOnEndOfStatement = true;
else if (!open && tok->varId() == var->declarationId()) else if (_tokenizer->isCPP() && tok->str() == "try") {
open = false;
break;
} else if (!open && tok->varId() == var->declarationId())
va_list_usedBeforeStartedError(tok, var->name()); va_list_usedBeforeStartedError(tok, var->name());
else if (exitOnEndOfStatement && tok->str() == ";") else if (exitOnEndOfStatement && tok->str() == ";")
break; break;

View File

@ -116,6 +116,18 @@ private:
"}"); "}");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #6186
check("void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\n"
" va_list arg_ptr;\n"
" va_start(arg_ptr, szBuffer);\n"
" try {\n"
" throw sth;\n"
" } catch(...) {\n"
" va_end(arg_ptr);\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\n" check("void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\n"
" va_list arg_ptr;\n" " va_list arg_ptr;\n"
" va_start(arg_ptr, szBuffer);\n" " va_start(arg_ptr, szBuffer);\n"